It’s very expensive to load configurations and settings from XML files, on every requests.

First because of latency of accessing files from hard drive, second because of the XML
file parsing burden.

Because of that , we implemented in upcoming 1.8 version of DotKernel a cache layer where to store router, acl_role, menu, options(including seo_xml), browser_xml, os_xml, test between requests. More information about the variables which DotKernel cache by default follow this link: DotKernel Reserved Variable Names for Caching

We are implementing 2 different cache factories to choose from: apc (or apcu for newest PHP installations) and file.

1. Configuring the cache

The configuration can be set from /configs/application.ini, you can choose if you use the caching system, how long your cache stays valid, the cache namespace, and the storage provider (File or APC). I would disable the cache in development mode if I were you.

For more info about the configuration and help configuring the cache see: Configuring the Cache in DotKernel.

2. Using the Cache

The cache is automatically loaded in the initialization and stored in the Registry.

Loading the caching engine is not needed because it is already loaded on kernel initialization (see Dot_Kernel::initialize($startTime)), but if you would like to use caching for other purposes (where you are not initializing the kernel), the loading syntax is the following:

Dot_Cache::loadCache();

Below is a simple object caching sample, yes, you can also cache objects.

Note: The cache key must match the following RegEx pattern: [A-Za-z0-9_]*

$id = 'MyCachedKey';
$obj = new stdClass();
$obj->text = 'I am a cached text';

// saving an object
Dot_Cache::save(obj, $id);

// loading the object
$value = Dot_Cache::load($id);

// checking if we have the object in cache
if($value !== false)
{
     // assuming we only need the text value from the object
     echo $value->text;
}
else
{
     echo 'no value cached for '. $id ; 
}

2 Comments

  1. DotKernel Reserved Variable Names for Caching | DotKernel PHP Application Framework

    […] This article is related to: Caching in DotKernel with Zend Framework Cache […]

  2. DotKernel 1.8.0 LTS Released | DotKernel PHP Application Framework

    […] The DotKernel framework just got a big boost because it supports APC & File Caching within the framework, all the XML’s and config files are cached in order to maximize response speed for more information about caching and how to cache your data see this article. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>