One of the latest implemented features of CppCMS is a caching system.
Each cached entry is stored using:
- Unique key that defines the entry
- An actual data
- Entry lifetime period.
- The set of triggers --- this is a feature that is not available in many cache system like memcached.
For example: main page that displays 5 recent posts may have a key
main_page and triggers:
post_124, ... ,
post_128. More then that, each time, during page build, when you fetch some cached data, like a sidebar or set of options, their sets of triggers are automatically added to the set of triggers of the page you build.
For example, when the page is created and sidebar block is fetched from cache all its triggers are automatically added: if
sidebar depends of
options, then trigger
options will be automatically added to triggers of
Thus, when certain trigger is risen, all pages that depends on it are automatically trashed. This makes a cache system quite powerful and easy to control correct data representation.
The developer is expected to create a rational model of data/triggers that represent the relations between parts of internal data and rise these triggers when committing changes to database.
There are 3 data types that can be stored in cache:
- Page: consists of a full html/xml output page and its gzip compressed copy.
- Partial HTML content: parts of page like "sidebar", "signature" or others that can be reused in many places. They are actually represented as
- Any C++ Object that inherits
serializableclass and implements methods for storing and restoring itself. It is useful for caching of DB data or any suitable C++ object.
As in case of different worker/API modes, cache interface has several independent working models, more then that, it can be easily extended with new one.
There are 4 caching modules that will be shipped with CppCMS:
- None --- the cache is disabled --- default mode.
- Thread shared -- only different threads of same process has an access to the cache --- to be used with thread pool worker model.
- Fork shared1 -- different processes that were forked from the same parent can access the cache placed in shared memory --- to be used with mod prefork.
- Distributed2 -- client-server model similar to memcached but more powerful due to support of triggers. It should be used on distributed systems or with mod process.
If your cache implementation does not relay on triggers and uses timeouts only all cache modes can be mixed with all worker modes.
This blog runs using mod-prefork and uses fork shared cache.
- Fork caching mode is actually thread cache placed almost as-is to shared memory segment.
- Distributed cache is not implemented yet. Will be done for next beta releases.