The Cache facade provided by the Lion Framework eases you to manage the cache usage within your application as well as define declarativelly or programatically your own caching policies.
However, it's important to note that Lion hasn't his own cache implementation since there are really excelents solutions out there. Instead of it, Lion brings a facade as an integrated way to manage cache.
By default, Lion framework has a facade to Cache Lite as well as MemCache, 2 of the most mature and completed PHP caching solutions.
However, we are working in order to provide facades to others great caching frameworks such APC.
In general, cache facade has been designed to work against whatever cache framework, so we are not binding our application to a concrete implementation at all.
Cache is enabled by default, meaning that every time you perform changes within the configuration, you may delete the cache to reflect your changes.
Take into account that configuration is pre-processed and stored in cache to accelerate the performance.
Configuring the Cache facade
The app/lion.ini file has the following cache configuration by default:
;-------------------------------------
; CACHE DIRECTIVES:
;-------------------------------------
;GLOBAL CACHE DIRECTIVES:
CACHE_ENABLED = yes
;Cache handler class to use:
CACHE_HANDLER_CLASS = "__CacheLite"
;Where cache files will be placed (in case a file based cache)
CACHE_FILE_DIR = "var/code_c"
;MEMCACHE SPECIFIC DIRECTIVES:
;Memcache server (default: localhost)
;MEMCACHE_SERVER = "localhost"
;Memcache port (default port: 11211)
;MEMCACHE_PORT = 11211
...
Note that default facade points to __CacheLite. However, we can change it in order to use the MemCache facade by changing the CACHE_HANDLER_CLASS directive to use the __MemCache facade
Cache facade API
Cache facade works against specific cache handler implementations, so it exposes a defined interface working against whatever implementation like MemCache, APC, etc...
To retrieve the cache handler associated to our application context, we just need to call the __ContextContainer::getCache() method:
//store data to cache, so next time won't be needed to
//get it from the database but from the cache:
$cache->setData('data', $data);
}
Cache TTL
TTL is the expiration time of an item within the cache.
If it's equal to zero, the item will never expire. You can use a number of seconds starting from current time, but in any case the number of seconds may not exceed 2592000 (30 days).