public static function configure(array $config = null) { if (empty($config) or empty($config["store"])) { $store = "null"; } else { $store = $config["store"]; } // if we've passed custom Store instance if (!is_string($store)) { $storeInterface = $store; } else { $storeConfig = isset($config[$store]) ? $config[$store] : array(); if ($store == "memcached") { $storeInterface = MemcachedStore::factory($storeConfig); } elseif ($store == "memcache") { $storeInterface = MemcacheStore::factory($storeConfig); } elseif ($store == "apc") { $storeInterface = new ApcStore($storeConfig); } elseif ($store == "file") { $storeInterface = new FileStore($storeConfig["path"]); } elseif ($store == "null") { $storeInterface = new NullStore(); } else { $storeInterface = DI::reflect($store, $storeConfig); } } // creating new SugiPHP\Cache instance $instance = new SugiPhpCache($storeInterface); // check we want keys prefix if (!empty($config["prefix"])) { $instance->setPrefix($config["prefix"]); } // save it static::$instance = $instance; }
/** * @return SugiPHP\Cache\Cache */ protected function prepareCache($config = []) { // check store type - use ArrayStore as default $store = isset($config["store"]) ? $config["store"] : "array"; unset($config["store"]); // check we want keys prefix $prefix = isset($config["prefix"]) ? $config["prefix"] : $this["uri"]->getHost(); unset($config["prefix"]); // if we've passed custom Store instance if (!is_string($store)) { $storeInterface = $store; } else { if ($store == "memcached") { $storeInterface = MemcachedStore::factory($config); } elseif ($store == "memcache") { $storeInterface = MemcacheStore::factory($config); } elseif ($store == "apcu") { $storeInterface = new ApcuStore($config); } elseif ($store == "apc") { $storeInterface = new ApcStore($config); } elseif ($store == "file") { $path = isset($config["path"]) ? $config["path"] : $this["temp_path"]; $storeInterface = new FileStore(); } elseif ($store == "array") { $storeInterface = new ArrayStore(); } else { // If there is no match, or "null" is specified -> use NullStore. No cache is done! $storeInterface = new NullStore(); } } // creating new SugiPHP\Cache instance $cache = new Cache($storeInterface); // setting prefix $cache->setPrefix($prefix); return $cache; }