From 6d5480ecfb09487fd04fd462716515c9b6544787 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 17 Apr 2016 00:36:25 +0900 Subject: [PATCH] Add Cache class and CacheInterface for drivers --- common/autoload.php | 5 + common/framework/cache.php | 247 ++++++++++++++++++++ common/framework/drivers/cacheinterface.php | 113 +++++++++ 3 files changed, 365 insertions(+) create mode 100644 common/framework/cache.php create mode 100644 common/framework/drivers/cacheinterface.php diff --git a/common/autoload.php b/common/autoload.php index 783fe1a52..d1720fc07 100644 --- a/common/autoload.php +++ b/common/autoload.php @@ -202,3 +202,8 @@ Rhymix\Framework\Debug::registerErrorHandlers(error_reporting()); */ $internal_timezone = Rhymix\Framework\DateTime::getTimezoneNameByOffset(config('locale.internal_timezone')); date_default_timezone_set($internal_timezone); + +/** + * Initialize the cache handler. + */ +Rhymix\Framework\Cache::init(Rhymix\Framework\Config::get('cache')); diff --git a/common/framework/cache.php b/common/framework/cache.php new file mode 100644 index 000000000..3ccf075ac --- /dev/null +++ b/common/framework/cache.php @@ -0,0 +1,247 @@ +incr(self::getRealKey('#GROUP:' . $group_name . ':v'), 1) ? true : false; + } + else + { + return false; + } + } + + /** + * Clear all keys from the cache. + * + * This method returns true on success and false on failure. + * + * @return bool + */ + public static function clearAll() + { + if (self::$_driver !== null) + { + return self::$_driver->clear() ? true : false; + } + else + { + return false; + } + } + + /** + * Get the actual key used by Rhymix. + * + * @param string $key + * @param string $group_name (optional) + * @return string + */ + public static function getRealKey($key, $group_name = null) + { + if ($group_name) + { + $group_version = intval(self::get('#GROUP:' . $group_name . ':v')); + return self::getCachePrefix() . '#GROUP:' . $group_name . ':' . $group_version . ':' . $key; + } + else + { + return self::getCachePrefix() . $key; + } + } +} diff --git a/common/framework/drivers/cacheinterface.php b/common/framework/drivers/cacheinterface.php new file mode 100644 index 000000000..117e67d45 --- /dev/null +++ b/common/framework/drivers/cacheinterface.php @@ -0,0 +1,113 @@ +