Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hailwood
Created May 23, 2016 22:12
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 hailwood/13b346337a3d62bd674f52fbc176b858 to your computer and use it in GitHub Desktop.
Save hailwood/13b346337a3d62bd674f52fbc176b858 to your computer and use it in GitHub Desktop.
<?php
class SomeClass implements Flushable {
protected static $cache_key = 'my_cache_key';
protected static function init()
{
if (!self::$initialized) {
$cacheDir = BASE_PATH . DIRECTORY_SEPARATOR . 'localcache' . DIRECTORY_SEPARATOR . self::$cache_key;
if(!@is_writable($cacheDir)){
$oldUmask = umask();
umask(0);
mkdir($cacheDir, 0777);
umask($oldUmask);
}
SS_Cache::add_backend(self::$cache_key, 'File', ['cache_dir' => $cacheDir]);
SS_Cache::set_cache_lifetime(self::$cache_key, (4 * 60 * 60), 10);
SS_Cache::pick_backend(self::$cache_key, self::$cache_key, 10);
self::$initialized = true;
}
}
public static function flush(){
self::init();
$cache = SS_Cache::factory(self::$cache_key);
$cache->save('some value', 'some_key');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment