Home » Phalcon Cache

Cache

Cache is a class found under PhalconCache directory. It helps in accessing frequently used data at much faster rate. PhalconCache is written in C Programming language and reduce overhead.

When to implement Cache?

  1. When we are frequently using complex calculations that returns the same result.
  2. When we are using many helpers and the output generated is always the same.
  3. When we are accessing database data constantly and its data rarely changes.

Caching process is divided into 2 parts:

1) Frontend: Frontend checks whether a key has expired or not. Also perform additional transformations to the data before storing and after retrieving them from the backend.

2) Backend: Backend part is responsible for communicating, reading or writing the data required by the frontend.

Implementation

Below code provide basic caching process for 2 days cache by implementing frontend and backend adapters.


Frontend Adapters

Adapter Description
PhalconCacheFrontendOutput Read input data from standard PHP output.
PhalconCacheFrontendData It is used to cache any kind of PHP data (big arrays, objects, text, etc). Data is serialized before stored in the backend.
PhalconCacheFrontendBase64 It’s used to cache binary data. The data is serialized using base64_encode before be stored in the backend.
PhalconCacheFrontendJson Data is encoded in JSON before be stored in the backend. Decoded after be retrieved. This frontend is useful to share data with other languages or frameworks.
PhalconCacheFrontendIgbinary It is used to cache any kind of PHP data (big arrays, objects, text, etc). Data is serialized using Igbinary before be stored in the backend.
PhalconCacheBackendXcache Stores data in XCache.
PhalconCacheBackendNone It is used to cache any kind of PHP data without serializing them.

Backend Adapters

Adapter Description Info Required Extension
PhalconCacheBackendApc Stores data to the Alternative PHP Cache (APC). APC APC
PhalconCacheBackendApcu Stores data to the APCu (APC without opcode caching) APCu APCu
PhalconCacheBackendFile Stores data to local plain files
PhalconCacheBackendMongo Stores data to Mongo Database. MongoDB MongoDB
PhalconCacheBackendRedis Stores data in Redis Redis Redis
PhalconCacheBackendXcache Stores data in XCache. XCache XCache
PhalconCacheBackendMemcache Stores data to a memcached server. Memcache Memcache

You may also like