get ready for Smarty apc caching

This commit is contained in:
Ian 2014-06-08 19:27:56 +02:00
parent d0d78f3450
commit 50344b19c0
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,61 @@
<?php
/**
* APC CacheResource for Smarty 3.1.x
*
* CacheResource Implementation based on the KeyValueStore API to use
* apc as the storage resource for Smarty's output caching.
*
*/
class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore {
public function __construct()
{
if(!function_exists('apc_cache_info'))
throw new Exception('APC Template Caching Error: APC is not installed');
}
/**
* Read values for a set of keys from cache
*
* @param array $keys list of keys to fetch
* @return array list of values with the given keys used as indexes
* @return boolean true on success, false on failure
*/
protected function read(array $keys)
{
return apc_fetch($keys);
}
/**
* Save values for a set of keys to cache
*
* @param array $keys list of values to save
* @param int $expire expiration time
* @return boolean true on success, false on failure
*/
protected function write(array $keys, $expire=null)
{
return apc_store($keys, null, $expire);
}
/**
* Remove values from cache
*
* @param array $keys list of keys to delete
* @return boolean true on success, false on failure
*/
protected function delete(array $keys)
{
foreach ($keys as $k) {
apc_delete($k);
}
return true;
}
/**
* Remove *all* values from cache
*
* @return boolean true on success, false on failure
*/
protected function purge()
{
return apc_clear_cache('user');
}
}

View File

@ -167,6 +167,10 @@ class Serendipity_Smarty extends Smarty
Set Smarty caching Set Smarty caching
*/ */
// enable for APC in-memory (RAM) storage caching - must be enabled in PHP
#apc-cache# $this->addPluginsDir ( SMARTY_DIR . 'plugins/' );
#apc-cache# $this->caching_type = 'apc'; //$this->setCachingType ( 'apc' );
/* /*
Caching is disabled, as long as we haven't figured out on how to use it best here.... Caching is disabled, as long as we haven't figured out on how to use it best here....