Deutschland United States United Kingdom
ContentLion - Open Source CMS

Caching

With caching you can improve the performance of your plugin. So database queries or complex calculatings aren't executed each time the site is loaded.

We are offering two variants of caching:

Usage

The samples of this sites are using the FileCache. Just change the name and you use another cache.

The first thing we need to do is storing some data in our cache. Look here:

FileCache::setData("page", $page->id, $page); 

The first parameter is the type we want to save. This should be a unique name for each data type, so have a look to our namespaces. In the second parameter you have to give a string, that indicates your object. You need to know this parameter, when you want to read your data later. The last parameter is the object you want to save. The datatype is similar.

What's a cache without a method to read from it? So let's fetch the data from cache:

FileCache::getData("page", $pageid);

Before you read from this cache, you can check, if the cache contains your data. Here is the code for that:

FileCache::contains("page", $pageid);