Skip to content

Instantly share code, notes, and snippets.

@Yalme
Last active October 10, 2021 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yalme/3a0190497daf00524bc535cd1a9796b3 to your computer and use it in GitHub Desktop.
Save Yalme/3a0190497daf00524bc535cd1a9796b3 to your computer and use it in GitHub Desktop.
// подключаем автолоад и запускаем общий кеш
require_once $PATHS['FILE']['ROOT'].'system'.DS.'vendor'.DS.'autoload.php';
use Phpfastcache\CacheManager;
use Phpfastcache\Config\ConfigurationOption;
CacheManager::setDefaultConfig(new ConfigurationOption([
'path' => $PATHS['FILE']['ROOT'].'system'.DS.'cache'.DS, // or in windows "C:/tmp/" // 'path' => sys_get_temp_dir(),
]));
$cache = CacheManager::getInstance('files');
// Тест работы кеша
$cache_key = 'test';
$cache_item = $cache->getItem($cache_key);
// if (is_admin()) $cache->deleteItemsByTag('h'.$host_id.'-comments');
// $cache->deleteItem($cache_key);
// $cache->deleteItemsByTag('comments');
// $cache->deleteItemsByTag('h'.$host_id.'-comments');
if ($cache_item->isHit()) {
// время кеша еще не истекло
$data = $cache_item->get();
debug('from cache');
debug($data);
} else {
$data = '8fds8fds8';
$cache_item->set($data)->expiresAfter(60*60*24*30*12)->addTags(['some_tag']); // secs
$cache->save($cache_item);
debug('cache setted');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment