InterJinn

Development Framework For PHP

Caches

Another widely used mechanism in any application is caching. Caching decreases the time needed to load some data or information by delegating the data to some easily accessible medium (ex. local hard drive versus remote site on the Internet). InterJinnTM comes complete with its own cache service, for which strong use is made by the Property System. As with most data storage services that are pre-package with InterJinn, the cache service comes complete with both a filesystem storage mechanism and an SQL storage mechanism (the exact SQL type depends on the database service which by default is MySQL). You may configure your project to use whichever suits your needs or you may write your own cache service to provide whatever functionality you would like.

The cache service implements three principles to facilitate an entry into the cache. These are a group for the data, a name, and a lifespan. The group is perhaps not entirely necessary but it enables related data to be grouped together, thus making it simple to delete related entries from both the filesystem or the database table. The name refers to some keyword used to access the data from its respective group, and the lifespan indicates how long the data should be considered valid. Following is an example of creating and saving a cache entry:

Example:
$cacheManager = $this->getService( 'cacheManager' );
$cache = $cacheManager->do->getCache( 'news', 'localReport' );
if( $cache->do->isExpired() ) { $content = someFunctionToRetrieveLocalNewsReport(); $content = someContentFormattingFunction( $content );
$cache->do->setData( $content ); $cache->do->setLifeSpan( 60 * 60 ); // In seconds, so 1 hour. } else { $content = $cache->do->getData(); }
echo $content;

Where can I learn more about the cache service?

To learn more about the cache service you can read the Cache Service Documentation. The same documentation will provide you with a list of methods and functionality that must exist in your own session service should you choose to create a custom one. You might also find the general Service Documentation useful.