Просмотр исходного кода

[GENERIC] I18N:

- finished tag support for caching

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22712 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 15 лет назад
Родитель
Сommit
025f80080b
4 измененных файлов с 80 добавлено и 11 удалено
  1. 1 0
      library/Zend/Date.php
  2. 34 3
      library/Zend/Date/DateObject.php
  3. 4 5
      library/Zend/Locale.php
  4. 41 3
      library/Zend/Locale/Data.php

+ 1 - 0
library/Zend/Date.php

@@ -274,6 +274,7 @@ class Zend_Date extends Zend_Date_DateObject
                             }
 
                             parent::$_cache = $value;
+                            parent::$_cacheTags = Zend_Date_DateObject::_getTagSupportForCache();
                             Zend_Locale_Data::setCache($value);
                         }
                         break;

+ 34 - 3
library/Zend/Date/DateObject.php

@@ -33,6 +33,7 @@ abstract class Zend_Date_DateObject {
      */
     private   $_unixTimestamp;
     protected static $_cache         = null;
+    protected static $_cacheTags     = false;
     protected static $_defaultOffset = 0;
 
     /**
@@ -254,7 +255,11 @@ abstract class Zend_Date_DateObject {
         }
 
         if (isset(self::$_cache)) {
-            self::$_cache->save( serialize($date), $id);
+            if (self::$_cacheTags) {
+                self::$_cache->save( serialize($date), $id, array('Zend_Date'));
+            } else {
+                self::$_cache->save( serialize($date), $id);
+            }
         }
 
         return $date;
@@ -340,7 +345,11 @@ abstract class Zend_Date_DateObject {
             }
 
             if (isset(self::$_cache)) {
-                self::$_cache->save( serialize($timestamp), $idstamp);
+                if (self::$_cacheTags) {
+                    self::$_cache->save( serialize($timestamp), $idstamp, array('Zend_Date'));
+                } else {
+                    self::$_cache->save( serialize($timestamp), $idstamp);
+                }
             }
         }
 
@@ -828,7 +837,11 @@ abstract class Zend_Date_DateObject {
         }
 
         if (isset(self::$_cache)) {
-            self::$_cache->save( serialize($array), $id);
+            if (self::$_cacheTags) {
+                self::$_cache->save( serialize($array), $id, array('Zend_Date'));
+            } else {
+                self::$_cache->save( serialize($array), $id);
+            }
         }
 
         return $array;
@@ -1055,4 +1068,22 @@ abstract class Zend_Date_DateObject {
 
         return $offset;
     }
+
+    /**
+     * Internal method to check if the given cache supports tags
+     *
+     * @param Zend_Cache $cache
+     */
+    protected static function _getTagSupportForCache()
+    {
+        $backend = self::$_cache->getBackend();
+        if ($backend instanceof Zend_Cache_Backend_ExtendedInterface) {
+            $cacheOptions = $backend->getCapabilities();
+            self::$_cacheTags = $cacheOptions['tags'];
+        } else {
+            self::$_cacheTags = false;
+        }
+
+        return self::$_cacheTags;
+    }
 }

+ 4 - 5
library/Zend/Locale.php

@@ -931,9 +931,7 @@ class Zend_Locale
     public static function getCache()
     {
         require_once 'Zend/Locale/Data.php';
-        $cache = Zend_Locale_Data::getCache();
-
-        return $cache;
+        return Zend_Locale_Data::getCache();
     }
 
     /**
@@ -973,12 +971,13 @@ class Zend_Locale
     /**
      * Clears all set cache data
      *
+     * @param string $tag Tag to clear when the default tag name is not used
      * @return void
      */
-    public static function clearCache()
+    public static function clearCache($tag = null)
     {
         require_once 'Zend/Locale/Data.php';
-        Zend_Locale_Data::clearCache();
+        Zend_Locale_Data::clearCache($tag);
     }
 
     /**

+ 41 - 3
library/Zend/Locale/Data.php

@@ -61,6 +61,13 @@ class Zend_Locale_Data
     private static $_cache = null;
 
     /**
+     * Internal value to remember if cache supports tags
+     *
+     * @var boolean
+     */
+    private static $_cacheTags = false;
+
+    /**
      * Internal option, cache disabled
      *
      * @var    boolean
@@ -901,7 +908,11 @@ class Zend_Locale_Data
         }
 
         if (isset(self::$_cache)) {
-            self::$_cache->save( serialize($temp), $id);
+            if (self::$_cacheTags) {
+                self::$_cache->save( serialize($temp), $id, array('Zend_Locale'));
+            } else {
+                self::$_cache->save( serialize($temp), $id);
+            }
         }
 
         return $temp;
@@ -1404,7 +1415,11 @@ class Zend_Locale_Data
             $temp = current($temp);
         }
         if (isset(self::$_cache)) {
-            self::$_cache->save( serialize($temp), $id);
+            if (self::$_cacheTags) {
+                self::$_cache->save( serialize($temp), $id, array('Zend_Locale'));
+            } else {
+                self::$_cache->save( serialize($temp), $id);
+            }
         }
 
         return $temp;
@@ -1428,6 +1443,7 @@ class Zend_Locale_Data
     public static function setCache(Zend_Cache_Core $cache)
     {
         self::$_cache = $cache;
+        self::_getTagSupportForCache();
     }
 
     /**
@@ -1461,7 +1477,11 @@ class Zend_Locale_Data
      */
     public static function clearCache()
     {
-        self::$_cache->clean();
+        if (self::$_cacheTags) {
+            self::$_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('Zend_Locale'));
+        } else {
+            self::$_cache->clean(Zend_Cache::CLEANING_MODE_ALL);
+        }
     }
 
     /**
@@ -1473,4 +1493,22 @@ class Zend_Locale_Data
     {
         self::$_cacheDisabled = (boolean) $flag;
     }
+
+    /**
+     * Internal method to check if the given cache supports tags
+     *
+     * @param Zend_Cache $cache
+     */
+    private static function _getTagSupportForCache()
+    {
+        $backend = self::$_cache->getBackend();
+        if ($backend instanceof Zend_Cache_Backend_ExtendedInterface) {
+            $cacheOptions = $backend->getCapabilities();
+            self::$_cacheTags = $cacheOptions['tags'];
+        } else {
+            self::$_cacheTags = false;
+        }
+
+        return self::$_cacheTags;
+    }
 }