-
-
Save hailwood/13b346337a3d62bd674f52fbc176b858 to your computer and use it in GitHub Desktop.
This file contains 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
<?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