Set version to 5.20.beta1
[civicrm-core.git] / CRM / Utils / Cache / ArrayCache.php
index c2a313af030ee033fc84c90b48d7b9b5637c11e7..c83f3f1f4eb63448bfaef67f2226ffd78e14f2e7 100644 (file)
  */
 
 /**
- * Class CRM_Utils_Cache_Arraycache
+ * Class CRM_Utils_Cache_ArrayCache
  */
-class CRM_Utils_Cache_Arraycache implements CRM_Utils_Cache_Interface {
+class CRM_Utils_Cache_ArrayCache implements CRM_Utils_Cache_Interface {
 
   use CRM_Utils_Cache_NaiveMultipleTrait;
-  use CRM_Utils_Cache_NaiveHasTrait; // TODO Native implementation
+  // TODO Native implementation
+  use CRM_Utils_Cache_NaiveHasTrait;
 
   const DEFAULT_TIMEOUT = 3600;
 
   /**
    * The cache storage container, an in memory array by default
+   * @var array
    */
   protected $_cache;
 
@@ -54,11 +56,11 @@ class CRM_Utils_Cache_Arraycache implements CRM_Utils_Cache_Interface {
    * @param array $config
    *   An array of configuration params.
    *
-   * @return \CRM_Utils_Cache_Arraycache
+   * @return \CRM_Utils_Cache_ArrayCache
    */
   public function __construct($config) {
-    $this->_cache = array();
-    $this->_expires = array();
+    $this->_cache = [];
+    $this->_expires = [];
   }
 
   /**
@@ -109,7 +111,7 @@ class CRM_Utils_Cache_Arraycache implements CRM_Utils_Cache_Interface {
   public function flush() {
     unset($this->_cache);
     unset($this->_expires);
-    $this->_cache = array();
+    $this->_cache = [];
     return TRUE;
   }
 
@@ -118,7 +120,25 @@ class CRM_Utils_Cache_Arraycache implements CRM_Utils_Cache_Interface {
   }
 
   private function reobjectify($value) {
-    return is_object($value) ? unserialize(serialize($value)) : $value;
+    if (is_object($value)) {
+      return unserialize(serialize($value));
+    }
+    if (is_array($value)) {
+      foreach ($value as $p) {
+        if (is_object($p)) {
+          return unserialize(serialize($value));
+        }
+      }
+    }
+    return $value;
+  }
+
+  /**
+   * @param string $key
+   * @return int|null
+   */
+  public function getExpires($key) {
+    return $this->_expires[$key] ?: NULL;
   }
 
 }