Changeset 638
- Timestamp:
- Sep 29, 2018 6:51:19 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Cache.inc.php
r611 r638 60 60 // The minimum items to keep in the cache regardless of item or cache size. 61 61 'min_items' => 5, 62 63 // How long in seconds before items in the cache are considered expired. 64 // When the cache expires, Cache->get() returns null. 65 'expires' => 3600, 62 66 ); 63 67 … … 187 191 188 192 // Save this value under the specified key. 189 $_SESSION['_cache'][$this->_ns][$key] =& $var; 193 $_SESSION['_cache'][$this->_ns][$key] = array( 194 'var' => $var, 195 'time' => time(), 196 ); 190 197 191 198 $app->logMsg(sprintf('Set cache item â%sâ', $key), LOG_DEBUG, __FILE__, __LINE__); … … 217 224 218 225 if (isset($_SESSION['_cache'][$this->_ns]) && array_key_exists($key, $_SESSION['_cache'][$this->_ns])) { 219 $app->logMsg(sprintf('Retrieving %s from cache.', $key), LOG_DEBUG, __FILE__, __LINE__); 220 // Move the accessed cached datum to the top of the stack. Maybe somebody knows a better way to do this? 221 $tmp =& $_SESSION['_cache'][$this->_ns][$key]; 222 unset($_SESSION['_cache'][$this->_ns][$key]); 223 $_SESSION['_cache'][$this->_ns][$key] =& $tmp; 224 // Return the unserialized datum. 225 return unserialize($_SESSION['_cache'][$this->_ns][$key]); 226 if (isset($_SESSION['_cache'][$this->_ns][$key]['time']) && $_SESSION['_cache'][$this->_ns][$key]['time'] > (time() - $this->getParam('expires'))) { 227 $app->logMsg(sprintf('Retrieving %s from cache.', $key), LOG_DEBUG, __FILE__, __LINE__); 228 // Move the accessed cached datum to the top of the stack. Maybe somebody knows a better way to do this? 229 $tmp =& $_SESSION['_cache'][$this->_ns][$key]; 230 unset($_SESSION['_cache'][$this->_ns][$key]); 231 $_SESSION['_cache'][$this->_ns][$key] =& $tmp; 232 // Return the unserialized datum. 233 return unserialize($_SESSION['_cache'][$this->_ns][$key]['var']); 234 } else { 235 // Cached item has expired. 236 $app->logMsg(sprintf('Cached %s expired %s ago', $key, humanTime(time() - $_SESSION['_cache'][$this->_ns][$key]['time'])), LOG_DEBUG, __FILE__, __LINE__); 237 return null; 238 } 226 239 } else { 227 240 $app->logMsg(sprintf('Missing %s from cache.', $key), LOG_DEBUG, __FILE__, __LINE__); … … 245 258 } 246 259 247 return (isset($_SESSION['_cache'][$this->_ns]) && array_key_exists($key, $_SESSION['_cache'][$this->_ns])); 260 if (isset($_SESSION['_cache'][$this->_ns]) 261 && array_key_exists($key, $_SESSION['_cache'][$this->_ns]) 262 && isset($_SESSION['_cache'][$this->_ns][$key]['time']) 263 && $_SESSION['_cache'][$this->_ns][$key]['time'] > (time() - $this->getParam('expires'))) { 264 $app->logMsg(sprintf('Cache item â%sâ exists', $key), LOG_DEBUG, __FILE__, __LINE__); 265 return true; 266 } else { 267 $app->logMsg(sprintf('Cache item â%sâ missing or expired', $key), LOG_DEBUG, __FILE__, __LINE__); 268 return false; 269 } 248 270 } 249 271
Note: See TracChangeset
for help on using the changeset viewer.