summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--demos/quickstart/protected/application.xml4
-rw-r--r--framework/Data/TAPCCache.php70
-rw-r--r--framework/Data/TMemCache.php5
-rw-r--r--framework/Exceptions/messages.txt4
-rw-r--r--requirements/index.php1
-rw-r--r--requirements/messages-zh.txt2
-rw-r--r--requirements/messages.txt2
7 files changed, 35 insertions, 53 deletions
diff --git a/demos/quickstart/protected/application.xml b/demos/quickstart/protected/application.xml
index 88cab8d1..b695f45b 100644
--- a/demos/quickstart/protected/application.xml
+++ b/demos/quickstart/protected/application.xml
@@ -2,9 +2,7 @@
<application id="QuickStart" Mode="Debug">
<modules>
- <!-- uncomment the following to enable caching
- <module id="cache" class="System.Data.TSqliteCache" />
- -->
+ <module id="cache" class="System.Data.TAPCCache" />
<!-- uncomment the following to enable logging to file
<module id="log" class="System.Log.TLogRouter">
<route class="TFileLogRoute" />
diff --git a/framework/Data/TAPCCache.php b/framework/Data/TAPCCache.php
index cef684fb..5c0a6eba 100644
--- a/framework/Data/TAPCCache.php
+++ b/framework/Data/TAPCCache.php
@@ -18,7 +18,10 @@
* By definition, cache does not ensure the existence of a value
* even if it never expires. Cache is not meant to be an persistent storage.
*
- * To use this module, the APC PHP extension must be loaded.
+ * To use this module, the APC PHP extension must be loaded and set in the php.ini file the following:
+ * <code>
+ * apc.cache_by_default=0
+ * </code>
*
* Some usage examples of TAPCCache are as follows,
* <code>
@@ -32,7 +35,7 @@
* cache module. It can be accessed via {@link TApplication::getCache()}.
*
* TAPCCache may be configured in application configuration file as follows
- * <module id="cache" type="System.Data.TAPCCache" Prefix="apc_cache_prefix_key_"/>
+ * <module id="cache" class="System.Data.TAPCCache" />
*
* @author Alban Hanry <compte_messagerie@hotmail.com>
* @version $Revision: $ $Date: $
@@ -41,9 +44,6 @@
*/
class TAPCCache extends TModule implements ICache
{
-
- const SERIALIZED = "_serialized";
-
/**
* @var boolean if the module is initialized
*/
@@ -62,38 +62,12 @@ class TAPCCache extends TModule implements ICache
*/
public function init($config)
{
- $application=$this->getApplication();
- if(!$application || $application->getMode()!==TApplication::STATE_PERFORMANCE)
- {
- if(!extension_loaded('apc'))
- throw new TConfigurationException('apccache_extension_required');
- }
- if($application) {
- if(!$this->_prefix)
- $this->_prefix=$application->getUniqueID();
- $application->setCache($this);
- }
- $this->_initialized=true;
- }
-
- /**
- * @return string prefix used to cache key
- */
- public function getPrefix()
- {
- return $this->_prefix;
- }
-
- /**
- * @param string prefix to be used for cache key
- * @throws TInvalidOperationException if the module is already initialized
- */
- public function setPrefix($value)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('apccache_prefix_unchangeable');
- else
- $this->_prefix=$value;
+ if(!extension_loaded('apc'))
+ throw new TConfigurationException('apccache_extension_required');
+ $application=$this->getApplication();
+ $this->_prefix=$application->getUniqueID();
+ $application->setCache($this);
+ $this->_initialized=true;
}
/**
@@ -102,7 +76,10 @@ class TAPCCache extends TModule implements ICache
*/
public function get($key)
{
- return apc_fetch($this->_prefix.$key);
+ if(($value=apc_fetch($this->_prefix.$key))!==false)
+ return Prado::unserialize($value);
+ else
+ return $value;
}
/**
@@ -118,41 +95,38 @@ class TAPCCache extends TModule implements ICache
*/
public function set($key,$value,$expiry=0)
{
- if(is_array($value))
- $value=new ArrayObject($value);
- return apc_store($this->_prefix.$key,$value,$expiry);
+ return apc_store($this->_prefix.$key,Prado::serialize($value),$expiry);
}
/**
* Stores a value identified by a key into cache if the cache does not contain this key.
- * Nothing will be done if the cache already contains the key.
+ * APC does not support this mode. So calling this method will raise an exception.
* @param string the key identifying the value to be cached
* @param mixed the value to be cached
* @param integer the expiration time of the value,
* 0 means never expire,
* @return boolean true if the value is successfully stored into cache, false otherwise
+ * @throw new TNotSupportedException if this method is invoked
*/
public function add($key,$value,$expiry=0)
{
- if(!apc_fetch($this->_prefix.$key))
- return $this->set($key,$value,$expiry);
- else return false;
+ throw new TNotSupportedException('apccache_add_unsupported');
}
/**
* Stores a value identified by a key into cache only if the cache contains this key.
* The existing value and expiration time will be overwritten with the new ones.
+ * APC does not support this mode. So calling this method will raise an exception.
* @param string the key identifying the value to be cached
* @param mixed the value to be cached
* @param integer the expiration time of the value,
* 0 means never expire,
* @return boolean true if the value is successfully stored into cache, false otherwise
+ * @throw new TNotSupportedException if this method is invoked
*/
public function replace($key,$value,$expiry=0)
{
- if(apc_fetch($this->_prefix.$key))
- return $this->set($key,$value,$expiry);
- else return false;
+ throw new TNotSupportedException('apccache_replace_unsupported');
}
/**
diff --git a/framework/Data/TMemCache.php b/framework/Data/TMemCache.php
index f6ff7da8..b2b1643d 100644
--- a/framework/Data/TMemCache.php
+++ b/framework/Data/TMemCache.php
@@ -111,9 +111,10 @@ class TMemCache extends TModule implements ICache
$this->_cache=new Memcache;
if($this->_cache->connect($this->_host,$this->_port)===false)
throw new TConfigurationException('memcache_connection_failed',$this->_host,$this->_port);
- $this->_prefix=$this->getApplication()->getUniqueID();
+ $application=$this->getApplication();
+ $this->_prefix=$application->getUniqueID();
+ $application->setCache($this);
$this->_initialized=true;
- $this->getApplication()->setCache($this);
}
/**
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt
index 481bb42d..c142d8a6 100644
--- a/framework/Exceptions/messages.txt
+++ b/framework/Exceptions/messages.txt
@@ -76,6 +76,10 @@ memcache_connection_failed = TMemCache failed to connect to memcache server %
memcache_host_unchangeable = TMemCache.Host cannot be modified after the module is initialized.
memcache_port_unchangeable = TMemCache.Port cannot be modified after the module is initialized.
+apccache_extension_required = TAPCCache requires APC PHP extension.
+apccache_add_unsupported = TAPCCache.add() is not supported.
+apccache_replace_unsupported = TAPCCache.replace() is not supported.
+
errorhandler_errortemplatepath_invalid = TErrorHandler.ErrorTemplatePath '%s' is invalid. Make sure it is in namespace form and points to a valid directory containing error template files.
pageservice_page_unknown = Page '%s' Not Found
diff --git a/requirements/index.php b/requirements/index.php
index 9a29d210..b28339b0 100644
--- a/requirements/index.php
+++ b/requirements/index.php
@@ -37,6 +37,7 @@ $requirements = array(
array(false,'extension_loaded("zlib")','Zlib check','Zlib extension optional'),
array(false,'extension_loaded("sqlite")','SQLite check','SQLite extension optional'),
array(false,'extension_loaded("memcache")','Memcache check','Memcache extension optional'),
+ array(false,'extension_loaded("apc")','APC cache check','APC extension optional'),
array(false,'extension_loaded("mcrypt")','Mcrypt check','Mcrypt extension optional'),
);
diff --git a/requirements/messages-zh.txt b/requirements/messages-zh.txt
index 9446ba41..4b3f4acc 100644
--- a/requirements/messages-zh.txt
+++ b/requirements/messages-zh.txt
@@ -8,6 +8,8 @@ SQLite check = SQLite模块检查
SQLite extension optional = SQLite模块是可选的。如果它不存在,您将无法使用TSQLiteCache。
Memcache check = Memcache模块检查
Memcache extension optional = Memcache模块是可选的。如果它不存在,您将无法使用TMemCache。
+APC cache check = APC缓存模块检查
+APC extension optional = APC模块是可选的。如果它不存在,您将无法使用TAPCCache。
Zlib check = Zlib模块检查
Zlib extension optional = Zlib模块是可选的。如果它不存在,页面的状态信息将无法压缩,由此可能导致您的页面传送数据量增大。
DOM extension required = DOM模块是必须的。如果它不存在,基于XML的各种配置文件将无法解析。
diff --git a/requirements/messages.txt b/requirements/messages.txt
index 1d0cc471..7abc3dbe 100644
--- a/requirements/messages.txt
+++ b/requirements/messages.txt
@@ -8,6 +8,8 @@ SQLite check = SQLite check
SQLite extension optional = SQLite extension is optional. If it is absent, you will not be able to use TSqliteCache.
Memcache check = Memcache check
Memcache extension optional = Memcache extension is optional. If it is absent, you will not be able to use TMemCache.
+APC cache check = APC cache check
+APC extension optional = APC extension is optional. If it is absent, you will not be able to use TAPCCache.
Zlib check = Zlib check
Zlib extension optional = Zlib extension is optional. If it is absent, page state will not be compressed and your page size may increase.
DOM extension required = DOM extension is required by PRADO. It is used in TXmlDocument to parse all sorts of XML-based configurations.