limit = $limit; return $this; } /* -( Key-Value Cache Implementation )------------------------------------- */ public function isAvailable() { return true; } public function getKeys(array $keys) { $results = array(); $now = time(); foreach ($keys as $key) { if (!isset($this->cache[$key]) && !array_key_exists($key, $this->cache)) { continue; } if (isset($this->ttl[$key]) && ($this->ttl[$key] < $now)) { continue; } $results[$key] = $this->cache[$key]; } return $results; } public function setKeys(array $keys, $ttl = null) { foreach ($keys as $key => $value) { $this->cache[$key] = $value; } if ($ttl) { $end = time() + $ttl; foreach ($keys as $key => $value) { $this->ttl[$key] = $end; } } else { foreach ($keys as $key => $value) { unset($this->ttl[$key]); } } if ($this->limit) { $count = count($this->cache); if ($count > $this->limit) { $remove = array(); foreach ($this->cache as $key => $value) { $remove[] = $key; $count--; if ($count <= $this->limit) { break; } } $this->deleteKeys($remove); } } return $this; } public function deleteKeys(array $keys) { foreach ($keys as $key) { unset($this->cache[$key]); unset($this->ttl[$key]); } return $this; } public function getAllKeys() { return $this->cache; } public function destroyCache() { $this->cache = array(); $this->ttl = array(); return $this; } }