ASISG

Gy - php framework/CMS | Documentation | Cache

<-- table of contents

Work with a cache

Work with cache in the admin panel

You can reset the cache, for this you need to go to the admin panel -> "Settings" and click the "reset cache" button. this will reset the entire cache created as in the example below.

Working with cache in code

Initially, you need to select a class for working with caches in gy_config.php settings, for today only cacheFiles is implemented - this is a class for working with file cache, i.e. the cache will be stored as files in the /gy/cache section - and the button described above simply deletes the contents of the folder. As a temporary solution, the cache class name is written into the global variable $cacheClassName and then work with it as with the class name.

Code usage example

It is necessary to initialize the cache (by specifying the name of the cache and time), if there is such a cache, then take data from it and if not, execute the code for receiving data and write data to the cache.

global $app;
global $cacheClassName;
$cache = new $cacheClassName($app->url);
$initCache = $cache->cacheInit('getAccessGroup', self::$cacheTimeGetData); // initialize cache

if ($initCache){
 $arResult = $cache->getCacheData(); // getting data from cache
}else{

 // !!! there should be a code for receiving data and writing it to $arResult

 $cache->setCacheData($arResult); // write data to cache
}

There is also a cache flush method for the current cache object, i.e. after initializing clearThisCache(). All methods can be viewed in the source here - gy/classes/cacheFiles.php

Sample cache file

<? $cacheData = '{"data":{"ITEMS":{"1":{"id":"1","id_container_data":"1","id_element_container_data":"1","id_property_container_data":"1","value":"\u041f\u0440\u0438\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u0442\u0435\u0431\u044f \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 gy php framework\n \u0438 \u0442\u0435\u043a\u0441\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u0438\u0437 \u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438!!!"}}},"createTime":1575221651,"cacheTime":86400}';


View documentation on GitHub.com