Caching

Caching provides class Cache defined in the file includes/cache.php.

We have two backend connection: file caching and caching Memcached. Default use file caching. In the site settings, you can enable the Memcached caching.

Cache action time is not limited. Cache clean when editing the module content from the administrative part.

In the module "Site Settings" there are two options cache management "Disable caching" and "Reset cache".

Методы

void close () – Closes a previously opened connection.

mixed get (string|array $name, string $module) – Reads module cache with tag.

  • string|array $name: tag
  • string $module: module name

The cache must be passed label all the conditions under which the content can be changed (page number, site language, etc.).

Example:

// request data from the cache to the first page of the module Question-Answer
$cache_meta = array(
    
// unique name
    
"name"     => "first_page",

    
// site language
    
"lang_id" => _LANG,

    
// page of site which is attached module
    
"site_id" => $this->diafan->_site->id,

    
// user group
    
"role_id" => $this->diafan->_users->role_id ? $this->diafan->_users->role_id : 0,

    
// time
    
"time"     => $time
);
$result = $this->diafan->_cache->get($cache_meta, "faq");

boolean save (mixed $data, string|array $name, string $module) – Saves data for module with tag.

  • mixed $data: data
  • string|array $name: tag
  • string $module: module name

Example:

$this->diafan->_cache->save($result, $cache_meta, "faq");

Methods get() and save() used together.

Example:

$cache_meta = array(
    
"name"     => "first_page",
    
"lang_id" => _LANG,
    
"site_id" => $this->diafan->_site->id,
    
"role_id" => $this->diafan->_users->role_id ? $this->diafan->_users->role_id : 0,
    
"time"     => $time
);
if(!
$result = $this->diafan->_cache->get($cache_meta, "faq"))
{
    
// generate data and write them in the variable $result

    // save caching
    
$this->diafan->_cache->save($result, $cache_meta, "faq");
}

boolean delete (string $name, [string $module = '']) – Removes the cache for module with tag. If the function is called with an empty label, then the entire cache for the module.

  • string $name: tag
  • string $module: module name

Example:

// delete cache of module "Online shop"
$this->diafan->_cache->delete("", "shop");

// delete cache of all modules
$this->diafan->_cache->delete("", array());