Main  /  Edit version 1  /  Edit version 2  /   /  Users Area

Difference "cppcms::cache_iface" ver. 1 versus ver. 2

Content:

## Role
This class provides access to cache API of cppcms;
This class provides access to cache API of cppcms. It is usually accessed by `cache` member of `application` or `worker_thread`.
In order to use cache, you should [enable it](/wikipp/en/page/ref_config#cache) in CppCMS configurations, otherwise, dummy cache would be used.
## Objects that are stored in cache:
1. Output pages -- including two versions compressed and not for user agents that support gzip compression or not.
2. HTML Frames -- or simple strings stored in cache.
3. [Serializable]((/wikipp/en/page/ref_cppcms_serializable) objects.
Each one of them has little bit different semantics and API.
## General
CppCMS provides sophisticated cache system that allows keep its consistency using special triggers that allow cleanup dependent groups of entries using single call.
However, in many cases, timeout only based approach is good enough. So, we would divide the API into two sections:
1. Trigger-less cache access
2. Full trigger based cache access
## Trigger-less cache access
### Web Page
- **`bool fetch_page(string const &key)`** -- fetch page from cache. If it is fetched, `true` is returned and output is prepared, otherwise false is returned.
_Note:_ The output is prepared according to request of user agent --- compressed or not compressed format. Thus, output stream may include already compressed data, so you should not try to append any output after you use this function.
- **`void store_page(string const &key,int timeout=-1);`** -- store prepared output in cache using `timeout` in seconds.
_Note_: default timeout = -1 -- infinite.
For example:
if(cache.fetch_page("main"))
return;
...
render(...)
cache.store_page("main",3600);
The page can be removed from cache calling:
- **`void rise(string const &key)`** -- that removes data associated with this key.

Sidebar:

## Related
- [Configuration: Cache](/wikipp/en/page/ref_config#cache)
- [cppcms::serializable](/wikipp/en/page/ref_cppcms_serializable)

About

CppCMS is a web development framework for performance demanding applications.

Support This Project

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page


Valid CSS | Valid XHTML 1.0