Caching Mechanisms

The PHP world benefits from a very large community that have done consistent work on most of the popular caching mechanisms available today. FRAPI takes advantage of the extensions and software engineering time that has already been invested by giving its developers the choice of using the mechanism of their choice. Those adapters are built-in FRAPI and require only a single line of code change in order for the developers to be taking full advantages of their favourite caching mechanisms.

This document will walk you through the subtleties of configuring your cache adapter:

Essential understanding

In order to use your caching adapter of choice, FRAPI requires the developers to manually modify the only configuration line that FRAPI currently has. The configuration file is located in FRAPI_PATH/src/frapi/custom/AllFiles.php. When you open that file, one might notice the only defined constant in that file called FRAPI_CACHE_ADAPTER. In order to use the caching mechanism of your choice, you will need to modify this to be either apc, memcached, redis, wincache, zenddisk, zendshm or dummy.

Please note that in future versions of FRAPI, the administration interface will allow developers to specify their caching adapters and servers.

Using APC as your caching mechanism

FRAPI employs the Alternative PHP Cache — APC — as the default caching adapter. This means that when you either clone or download FRAPI, the default FRAPI_CACHE_ADAPTER constant is set to apc.

If you do not have APC installed and you wish to run APC, you will need to follow the instructions here.

Using Memcached as your caching mechanism

If your favourite caching mechanism is Memcached, you may use the "memcached" caching adapter with FRAPI. Currently, the memcached caching adapter only connects to localhost by default. It is currently not possible to make FRAPI connect to a memcached-cluster for the configuration and internal caching. This is a feature coming in the short future.

It is possible to connect manually to a cluster of memcached servers in your models like such:

    $options = array(
        'servers' => array(
            '192.168.2.1' => 11211,
            '192.168.2.2' => 11211,
        )
    );
    
    $cache = Frapi_Cache::getInstance('memcached', $options);
    $cache->add('foo', 'bar');
    echo $cache->get('foo');
    $cache->delete('foo');
    

The FRAPI memcached adapter uses the PHP memcached extension. In order to install the memcached extension, please follow the instructions here.

Once you finished installing the extension and you restarted your webserver, set your FRAPI_CACHE_ADAPTER constant to memcached and FRAPI will now be interacting with the Memcached server on 127.0.0.1 and port 11211.

Note that it is also possible to use the memcache extension. In order to use the memcache adapter, you will need to modify your FRAPI_CACHE_ADAPTER constant and set it to memcache.

It is currently not possible to set the cluster information from the administration interface but it is a planned feature. Should you wish to modify the location of the default server, you have to modify the file FRAPI_PATH/src/frapi/library/Frapi/Cache/Adapter/Memcached.php to point to your own server. Again, it is important to note that this functionality will be added in the administration interface.

Using Redis as your caching mechanism

The FRAPI Redis caching adapter uses the phpredis extension from owlient. Should you wish to install the extension, please follow the instructions here.

Once you finished installing the extension and you restarted your webserver, set your FRAPI_CACHE_ADAPTER constant to redis and FRAPI will now be interacting with the Redis server on 127.0.0.1 and port 6379.

It is currently not possible to set the cluster information from the administration interface but it is a planned feature. Should you wish to modify the location of the default server, you have to modify the file FRAPI_PATH/src/frapi/library/Frapi/Cache/Adapter/Redis.php to point to your own server. Again, it is important to note that this functionality will be added in the administration interface.

Using WinCache as your caching mechanism

For developers who wish to use the WinCache caching mechanism, the first thing they will have to do is install the WinCache extension.

Once you finished installing the extension and you restarted your webserver, set your FRAPI_CACHE_ADAPTER constant to wincache and FRAPI will now be interacting with the WinCache caching mechanism.

Using Zend Disk as your caching mechanism

For developers using Zend Server, they have access to the Zend Disk caching mechanism. In order to use all the potential of the extension, the only thing developers using Zend Server have to do is set the FRAPI_CACHE_ADAPTER constant to zenddisk. This will automatically make FRAPI use the zenddisk caching mechanism.

Using Zend Shm as your caching mechanism

For developers using Zend Server, they have access to the Zend Shm caching mechanism. In order to use all the potential of the extension, the only thing developers using Zend Server have to do is set the FRAPI_CACHE_ADAPTER constant to zendshm. This will automatically make FRAPI use the zendshm caching mechanism.

Using without Caching

This is something we highly discourage considering the nature of the FRAPI configuration files that are normally cached. However, for developers that do not have a caching mechanism and that would wish to simply use FRAPI to test and experiment, one can set the FRAPI_CACHE_ADAPTER constant to dummy and FRAPI will act as if there was a caching adapter without doing actual caching.

Request a missing adapter

If you would like to see another caching adapter you can always propose a patch by forking us on github or if you have neither time nor interest to develop an adapter you'd like in FRAPI, you can always send an email to the frapi-dev mailing list requesting the caching adapter you want with documentation links — if possible.