Last active
October 10, 2021 16:07
-
-
Save Yalme/3a0190497daf00524bc535cd1a9796b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// подключаем автолоад и запускаем общий кеш | |
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