Consistenly allow setting prefix for cache entries.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 13 Jun 2010 17:12:50 +0000 (13:12 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 13 Jun 2010 17:12:50 +0000 (13:12 -0400)
For drivers where this makes sense, always allow setting a cache entry prefix
for preventing entry collisions from multiple horde instances on the same
physical box and for forcing the use of a certain prefix, regardless of the
servername we are hitting from. (This last point fixes an issue where a cache entry would
not expire when the entry was cached while accessing horde's data via the api from
a different virtual server).

framework/Cache/lib/Horde/Cache/Apc.php
framework/Cache/lib/Horde/Cache/Base.php
framework/Cache/lib/Horde/Cache/Eaccelerator.php
framework/Cache/lib/Horde/Cache/File.php
framework/Cache/lib/Horde/Cache/Memcache.php
framework/Cache/lib/Horde/Cache/Xcache.php
framework/Cache/lib/Horde/Cache/Zps4.php
horde/config/conf.php.mine [new file with mode: 0644]
horde/config/conf.xml

index 1416cc1..83c1771 100644 (file)
@@ -25,6 +25,7 @@ class Horde_Cache_Apc extends Horde_Cache_Base
      */
     public function get($key, $lifetime = 1)
     {
+        $key = $this->_params['prefix'] . $key;
         $this->_setExpire($key, $lifetime);
         return apc_fetch($key);
     }
@@ -40,6 +41,7 @@ class Horde_Cache_Apc extends Horde_Cache_Base
      */
     public function set($key, $data, $lifetime = null)
     {
+        $key = $this->_params['prefix'] . $key;
         $lifetime = $this->_getLifetime($lifetime);
         apc_store($key . '_expire', time(), $lifetime);
         return apc_store($key, $data, $lifetime);
@@ -56,6 +58,7 @@ class Horde_Cache_Apc extends Horde_Cache_Base
      */
     public function exists($key, $lifetime = 1)
     {
+        $key = $this->_params['prefix'] . $key;
         $this->_setExpire($key, $lifetime);
         return (apc_fetch($key) === false) ? false : true;
     }
@@ -69,6 +72,7 @@ class Horde_Cache_Apc extends Horde_Cache_Base
      */
     public function expire($key)
     {
+        $key = $this->_params['prefix'] . $key;
         apc_delete($key . '_expire');
         return apc_delete($key);
     }
@@ -81,6 +85,7 @@ class Horde_Cache_Apc extends Horde_Cache_Base
      */
     protected function _setExpire($key, $lifetime)
     {
+        $key = $this->_params['prefix'] . $key;
         if ($lifetime == 0) {
             // Don't expire.
             return;
index 9b3188c..2b5a17c 100644 (file)
@@ -50,6 +50,11 @@ abstract class Horde_Cache_Base
         }
 
         $this->_params = array_merge($this->_params, $params);
+        if (empty($this->_params['prefix'])) {
+            $this->_params['prefix'] = $_SERVER['SERVER_NAME']
+                ? $_SERVER['SERVER_NAME']
+                : $_SERVER['HOSTNAME'];
+        }
     }
 
     /**
index 2f65f06..a0919ed 100644 (file)
@@ -39,6 +39,7 @@ class Horde_Cache_Eaccelerator extends Horde_Cache_Base
      */
     public function get($key, $lifetime = 1)
     {
+        $key = $this->_params['prefix'] . $key;
         $this->_setExpire($key, $lifetime);
         return eaccelerator_get($key);
     }
@@ -54,6 +55,7 @@ class Horde_Cache_Eaccelerator extends Horde_Cache_Base
      */
     public function set($key, $data, $lifetime = null)
     {
+        $key = $this->_params['prefix'] . $key;
         $lifetime = $this->_getLifetime($lifetime);
         eaccelerator_put($key . '_expire', time(), $lifetime);
         return eaccelerator_put($key, $data, $lifetime);
@@ -70,6 +72,7 @@ class Horde_Cache_Eaccelerator extends Horde_Cache_Base
      */
     public function exists($key, $lifetime = 1)
     {
+        $key = $this->_params['prefix'] . $key;
         $this->_setExpire($key, $lifetime);
         return (eaccelerator_get($key) === false) ? false : true;
     }
@@ -83,6 +86,7 @@ class Horde_Cache_Eaccelerator extends Horde_Cache_Base
      */
     public function expire($key)
     {
+        $key = $this->_params['prefix'] . $key;
         eaccelerator_rm($key . '_expire');
         return eaccelerator_rm($key);
     }
@@ -101,6 +105,7 @@ class Horde_Cache_Eaccelerator extends Horde_Cache_Base
             return;
         }
 
+        $key = $this->_params['prefix'] . $key;
         $expire = eaccelerator_get($key . '_expire');
 
         // Set prune period.
index 80b03a1..43b113f 100644 (file)
@@ -23,20 +23,6 @@ class Horde_Cache_File extends Horde_Cache_Base
     protected $_dir;
 
     /**
-     * The filename prefix for cache files.
-     *
-     * @var string
-     */
-    protected $_prefix = 'cache_';
-
-    /**
-     * The subdirectory level the cache files should live at.
-     *
-     * @var integer
-     */
-    protected $_sub = 0;
-
-    /**
      * List of key to filename mappings.
      *
      * @var array
@@ -63,12 +49,12 @@ class Horde_Cache_File extends Horde_Cache_Base
             ? $params['dir']
             : Horde_Util::getTempDir();
 
-        if (isset($params['prefix'])) {
-            $this->_prefix = $params['prefix'];
+        if (!isset($params['prefix'])) {
+            $params['prefix'] = 'cache_';
         }
 
-        if (isset($params['sub'])) {
-            $this->_sub = intval($params['sub']);
+        if (!isset($params['sub'])) {
+            $params['sub'] = 0;
         }
 
         parent::__construct($params);
@@ -257,8 +243,8 @@ class Horde_Cache_File extends Horde_Cache_Base
             $dir = $this->_dir . '/';
             $sub = '';
             $md5 = md5($key);
-            if (!empty($this->_sub)) {
-                $max = min($this->_sub, strlen($md5));
+            if (!empty($this->_params['sub'])) {
+                $max = min($this->_params['sub'], strlen($md5));
                 for ($i = 0; $i < $max; $i++) {
                     $sub .= $md5[$i];
                     if ($create && !is_dir($dir . $sub)) {
@@ -270,7 +256,7 @@ class Horde_Cache_File extends Horde_Cache_Base
                     $sub .= '/';
                 }
             }
-            $this->_file[$key] = $dir . $sub . $this->_prefix . $md5;
+            $this->_file[$key] = $dir . $sub . $this->_params['prefix'] . $md5;
         }
 
         return $this->_file[$key];
@@ -296,14 +282,14 @@ class Horde_Cache_File extends Horde_Cache_Base
                 continue;
             }
 
-            if (strpos($entry, $this->_prefix) === 0) {
+            if (strpos($entry, $this->_params['prefix']) === 0) {
                 $d_time = isset($excepts[$path]) ? $excepts[$path] : $this->_params['lifetime'];
                 if (!empty($d_time) &&
                     (($c_time - $d_time) > filemtime($path))) {
                     @unlink($path);
                     unset($excepts[$path]);
                 }
-            } elseif (!empty($this->_sub) && is_dir($path)) {
+            } elseif (!empty($this->_params['sub']) && is_dir($path)) {
                 $this->_gcDir($path, $excepts);
             }
         }
index 36b05d5..364c8c1 100644 (file)
@@ -70,6 +70,7 @@ class Horde_Cache_Memcache extends Horde_Cache_Base
      */
     public function get($key, $lifetime = 1)
     {
+        $key = $this->_params['prefix'] . $key;
         if (isset($this->_expirecache[$key])) {
             return $this->_expirecache[$key];
         }
@@ -108,7 +109,9 @@ class Horde_Cache_Memcache extends Horde_Cache_Base
      */
     public function set($key, $data, $lifetime = null)
     {
+        $key = $this->_params['prefix'] . $key;
         $lifetime = $this->_getLifetime($lifetime);
+
         return ($this->_memcache->set($key . '_e', time(), $lifetime) === false)
             ? false
             : $this->_memcache->set($key, $data, $lifetime);
@@ -124,6 +127,8 @@ class Horde_Cache_Memcache extends Horde_Cache_Base
      */
     public function exists($key, $lifetime = 1)
     {
+        $key = $this->_params['prefix'] . $key;
+
         return ($this->get($key, $lifetime) !== false);
     }
 
@@ -136,8 +141,10 @@ class Horde_Cache_Memcache extends Horde_Cache_Base
      */
     public function expire($key)
     {
+        $key = $this->_params['prefix'] . $key;
         unset($this->_expirecache[$key]);
         $this->_memcache->delete($key . '_e');
+
         return $this->_memcache->delete($key);
     }
 
index 4fc8b02..1574845 100644 (file)
 class Horde_Cache_Xcache extends Horde_Cache_Base
 {
     /**
-     * Construct a new Horde_Cache_Xcache object.
-     *
-     * @param array $params  Configuration parameters:
-     * <pre>
-     * 'prefix' - (string) Key prefix.
-     * </pre>
-     */
-    public function __construct($params = array())
-    {
-        parent::__construct($params);
-
-        if (empty($this->_params['prefix'])) {
-            $this->_params['prefix'] = $_SERVER['SERVER_NAME']
-                ? $_SERVER['SERVER_NAME']
-                : $_SERVER['HOSTNAME'];
-        }
-    }
-
-    /**
      * Attempts to retrieve a piece of cached data and return it to the caller.
      *
      * @param string $key        Cache key to fetch.
@@ -107,12 +88,11 @@ class Horde_Cache_Xcache extends Horde_Cache_Base
      */
     protected function _setExpire($key, $lifetime)
     {
-        $key = $this->_params['prefix'] . $key;
         if ($lifetime == 0) {
             // don't expire
             return;
         }
-
+        $key = $this->_params['prefix'] . $key;
         $expire = xcache_get($key . '_expire');
 
         // set prune period
index 2e27d4b..f455be7 100644 (file)
@@ -25,6 +25,7 @@ class Horde_Cache_Zps4 extends Horde_Cache_Base
      */
     public function get($key, $lifetime = 1)
     {
+        $key = $this->_params['prefix'] . $key;
         return output_cache_get($key, $lifetime);
     }
 
@@ -39,6 +40,7 @@ class Horde_Cache_Zps4 extends Horde_Cache_Base
      */
     public function set($key, $data, $lifetime = null)
     {
+        $key = $this->_params['prefix'] . $key;
         output_cache_put($key, $data);
         return true;
     }
@@ -54,6 +56,7 @@ class Horde_Cache_Zps4 extends Horde_Cache_Base
      */
     public function exists($key, $lifetime = 1)
     {
+        $key = $this->_params['prefix'] . $key;
         $exists = output_cache_exists($key, $lifetime);
         output_cache_stop();
         return $exists;
@@ -68,6 +71,7 @@ class Horde_Cache_Zps4 extends Horde_Cache_Base
      */
     public function expire($key)
     {
+        $key = $this->_params['prefix'] . $key;
         return output_cache_remove_key($key);
     }
 
diff --git a/horde/config/conf.php.mine b/horde/config/conf.php.mine
new file mode 100644 (file)
index 0000000..fbec491
--- /dev/null
@@ -0,0 +1,133 @@
+<?php
+/* CONFIG START. DO NOT CHANGE ANYTHING IN OR AFTER THIS LINE. */
+// $Id: dd4b5b37397f084ee826751d6aee0bb5dca8d833 $
+$conf['vhosts'] = false;
+$conf['debug_level'] = E_ALL & ~E_DEPRECATED;
+$conf['max_exec_time'] = 0;
+$conf['compress_pages'] = false;
+$conf['secret_key'] = 'f3f2eb066cee536a156bf47ed7c403fa3800d975';
+$conf['umask'] = 077;
+$conf['testdisable'] = false;
+$conf['use_ssl'] = 0;
+$conf['server']['name'] = $_SERVER['SERVER_NAME'];
+$conf['server']['port'] = 80;
+$conf['urls']['token_lifetime'] = 30;
+$conf['urls']['hmac_lifetime'] = 30;
+$conf['urls']['pretty'] = false;
+$conf['safe_ips'] = array();
+$conf['session']['name'] = 'Horde';
+$conf['session']['use_only_cookies'] = true;
+$conf['session']['cache_limiter'] = 'nocache';
+$conf['session']['timeout'] = 0;
+$conf['cookie']['domain'] = '';
+$conf['cookie']['path'] = '/horde';
+$conf['sql']['persistent'] = true;
+$conf['sql']['username'] = 'root';
+$conf['sql']['password'] = 'ashley42';
+$conf['sql']['socket'] = '/opt/local/var/run/mysql5/mysqld.sock';
+$conf['sql']['protocol'] = 'unix';
+$conf['sql']['database'] = 'horde';
+$conf['sql']['charset'] = 'iso-8859-1';
+$conf['sql']['ssl'] = false;
+$conf['sql']['splitread'] = false;
+$conf['sql']['phptype'] = 'mysql';
+$conf['ldap']['useldap'] = false;
+$conf['auth']['admins'] = array('mike', 'mrubinsk');
+$conf['auth']['checkip'] = true;
+$conf['auth']['checkbrowser'] = true;
+$conf['auth']['alternate_login'] = false;
+$conf['auth']['redirect_on_logout'] = false;
+$conf['auth']['list_users'] = 'list';
+$conf['auth']['params']['app'] = 'imp';
+$conf['auth']['driver'] = 'application';
+$conf['signup']['allow'] = false;
+$conf['log']['priority'] = 'DEBUG';
+$conf['log']['ident'] = 'HORDE';
+$conf['log']['name'] = '/tmp/horde.log';
+$conf['log']['params']['append'] = true;
+$conf['log']['params']['format'] = 'default';
+$conf['log']['type'] = 'file';
+$conf['log']['enabled'] = true;
+$conf['log_accesskeys'] = false;
+$conf['prefs']['params']['driverconfig'] = 'horde';
+$conf['prefs']['driver'] = 'Sql';
+$conf['alarms']['params']['driverconfig'] = 'horde';
+$conf['alarms']['params']['ttl'] = 300;
+$conf['alarms']['driver'] = 'Sql';
+$conf['datatree']['driver'] = 'null';
+$conf['group']['driverconfig'] = 'horde';
+$conf['group']['driver'] = 'sql';
+$conf['group']['cache'] = true;
+$conf['perms']['driverconfig'] = 'horde';
+$conf['perms']['driver'] = 'Sql';
+$conf['share']['no_sharing'] = false;
+$conf['share']['world'] = true;
+$conf['share']['any_group'] = false;
+$conf['share']['hidden'] = false;
+$conf['share']['cache'] = false;
+$conf['share']['driver'] = 'sql';
+$conf['cache']['default_lifetime'] = 86400;
+$conf['cache']['params']['sub'] = 0;
+$conf['cache']['driver'] = 'File';
+$conf['cache']['use_memorycache'] = '';
+$conf['cachejs'] = false;
+$conf['cachecss'] = false;
+$conf['lock']['params']['driverconfig'] = 'horde';
+$conf['lock']['driver'] = 'Sql';
+$conf['token']['driver'] = 'Null';
+$conf['mailer']['params']['host'] = 'prod.theupstairsroom.com';
+$conf['mailer']['params']['localhost'] = 'macbook';
+$conf['mailer']['params']['auth'] = true;
+$conf['mailer']['params']['username'] = 'mike';
+$conf['mailer']['params']['password'] = 'n329sp';
+$conf['mailer']['type'] = 'smtp';
+$conf['mailformat']['brokenrfc2231'] = false;
+$conf['vfs']['params']['vfsroot'] = '/private/var/www/vfs';
+$conf['vfs']['type'] = 'file';
+$conf['sessionhandler']['type'] = 'Builtin';
+$conf['sessionhandler']['memcache'] = false;
+$conf['spell']['driver'] = '';
+$conf['gnupg']['keyserver'] = array('pgp.mit.edu');
+$conf['gnupg']['timeout'] = 10;
+$conf['image']['convert'] = '/opt/local/bin/convert';
+$conf['image']['identify'] = '/opt/local/bin/identify';
+$conf['image']['driver'] = 'Im';
+$conf['exif']['params']['exiftool'] = '/usr/bin/exiftool';
+$conf['exif']['driver'] = 'Exiftool';
+$conf['problems']['email'] = 'webmaster@example.com';
+$conf['problems']['maildomain'] = 'example.com';
+$conf['problems']['tickets'] = false;
+$conf['problems']['attachments'] = true;
+$conf['menu']['apps'] = array('ansel', 'horde', 'kronolith', 'turba');
+$conf['menu']['always'] = false;
+$conf['menu']['links']['help'] = 'all';
+$conf['menu']['links']['options'] = 'authenticated';
+$conf['menu']['links']['problem'] = 'all';
+$conf['menu']['links']['login'] = 'all';
+$conf['menu']['links']['logout'] = 'authenticated';
+$conf['portal']['fixed_blocks'] = array();
+$conf['weatherdotcom']['partner_id'] = '1004348024';
+$conf['weatherdotcom']['license_key'] = '15f65ed83a72d390';
+$conf['accounts']['driver'] = 'null';
+$conf['user']['verify_from_addr'] = false;
+$conf['api']['googlemaps'] = 'ABQIAAAAeLpMkRs_mXYrgoYSYk-zjhQle6r-2n9p_aVW9HzTuTHtJvxrbBQga60uPmHeQchudKTUsj6BCUPFWw';
+$conf['facebook']['key'] = '5fe552bd96b094ba52bec1cb27034539';
+$conf['facebook']['secret'] = '3a17c63e7d55878ad3bd4d44aea2f59f';
+$conf['facebook']['enabled'] = true;
+$conf['twitter']['enabled'] = false;
+$conf['imsp']['enabled'] = false;
+$conf['kolab']['enabled'] = false;
+$conf['memcache']['enabled'] = false;
+$conf['activesync']['state']['params']['devicetable'] = 'horde_activesync_device';
+$conf['activesync']['state']['params']['statetable'] = 'horde_activesync_state';
+$conf['activesync']['state']['params']['maptable'] = 'horde_activesync_map';
+$conf['activesync']['state']['params']['userstable'] = 'horde_activesync_device_users';
+$conf['activesync']['state']['driver'] = 'history';
+$conf['activesync']['logging']['path'] = '/tmp/activesync.txt';
+$conf['activesync']['logging']['type'] = 'custom';
+$conf['activesync']['ping']['forcedheartbeat'] = 60;
+$conf['activesync']['ping']['deviceping'] = false;
+$conf['activesync']['ping']['waitinterval'] = 2;
+$conf['activesync']['securitypolicies']['provisioning'] = false;
+$conf['activesync']['enabled'] = true;
+/* CONFIG END. DO NOT CHANGE ANYTHING IN OR BEFORE THIS LINE. */
index 9abcc4a..b575c68 100644 (file)
    select a driver here. This is used to speed up portions of Horde by storing
    commonly processed objects.">file
     <case name="Null" desc="Don't cache any objects"/>
-    <case name="Apc" desc="Use the APC cache"/>
+    <case name="Apc" desc="Use the APC cache">
+     <configsection name="params">
+      <configstring name="prefix" required="false" desc="The prefix to use for
+      cache entries."/>
+     </configsection>
+    </case>
     <case name="Eaccelerator" desc="Use the eAccelerator cache (up to version
     0.9.5)">
      <configdescription>
      you want to use the eAccelerator cache driver, you need version 0.9.5 or
      lower.
      </configdescription>
+     <configsection name="params">
+      <configstring name="prefix" required="false" desc="The prefix to use for
+      cache entries."/>
+     </configsection>
     </case>
     <case name="File" desc="Store objects in filesystem">
      <configsection name="params">
       use for the cache files."/>
      </configsection>
     </case>
-    <case name="Memcache" desc="Use a Memcache server"/>
+    <case name="Memcache" desc="Use a Memcache server">
+     <configsection name="params">
+      <configstring name="prefix" required="false" desc="The prefix to use for
+      cache entries."/>
+     </configsection>
+    </case>
     <case name="Sql" desc="SQL-based cache storage">
      <configsection name="params">
       <configsql switchname="driverconfig">
       </configsql>
      </configsection>
     </case>
-    <case name="Xcache" desc="Use the xCache cache"/>
-    <case name="Zps4" desc="Use the Zend Performance Suite output cache"/>
+    <case name="Xcache" desc="Use the xCache cache">
+     <configsection name="params">
+      <configstring name="prefix" required="false" desc="The prefix to use for
+      cache entries."/>
+     </configsection>
+    </case>
+    <case name="Zps4" desc="Use the Zend Performance Suite output cache">
+     <configsection name="params">
+      <configstring name="prefix" required="false" desc="The prefix to use for
+      cache entries."/>
+     </configsection>
+    </case>
    </configswitch>
    <configswitch name="use_memorycache" required="false" desc="Use a
    separate memory cache driver to store data in memory? If data is not found