-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made improvements to cache storage classes (#24)
* made improvements to cache storage classes * fixed incorrect logic in Cache::storage()
- Loading branch information
1 parent
d7e3a79
commit 9cdf200
Showing
5 changed files
with
97 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
* @package Cache_Storages | ||
* @author Gjero Krsteski <[email protected]> | ||
*/ | ||
abstract class Storage | ||
abstract class Storage implements \ArrayAccess | ||
{ | ||
/** | ||
* Determine if an item exists in the cache. | ||
|
@@ -26,6 +26,20 @@ public function has($key) | |
return ($this->get($key) !== null); | ||
} | ||
|
||
/** | ||
* Determine if an item exists in the cache. | ||
* | ||
* Enables you to use: isset($storage[$key]) | ||
* | ||
* @param $offset | ||
* | ||
* @return bool | ||
*/ | ||
public function offsetExists($offset) | ||
{ | ||
return $this->has($offset); | ||
} | ||
|
||
/** | ||
* Get an item from the cache. | ||
* | ||
|
@@ -47,6 +61,25 @@ public function get($key, $default = null) | |
return (!is_null($item = $this->retrieve($key))) ? $item : $default; | ||
} | ||
|
||
/** | ||
* Get an item from the cache. | ||
* | ||
* Enables you to use: $storage[$key] | ||
* | ||
* <code> | ||
* // Get an item from the cache storage | ||
* $name = Cache::storage()['name']; | ||
* </code> | ||
* | ||
* @param $offset | ||
* | ||
* @return mixed|null | ||
*/ | ||
public function offsetGet($offset) | ||
{ | ||
return $this->get($offset); | ||
} | ||
|
||
/** | ||
* Retrieve an item from the cache storage. | ||
* | ||
|
@@ -72,6 +105,19 @@ abstract protected function retrieve($key); | |
*/ | ||
abstract public function put($key, $value, $minutes); | ||
|
||
/** | ||
* Write an item to the cache for indefinite-term storage. | ||
* | ||
* Enables you to use: $storage[$key] = $value; | ||
* | ||
* @param $key | ||
* @param $value | ||
*/ | ||
public function offsetSet($key, $value) | ||
{ | ||
$this->forever($key, value); | ||
} | ||
|
||
/** | ||
* Get an item from the cache, or cache and return the default value. | ||
* | ||
|
@@ -101,6 +147,16 @@ public function remember($key, $default, $minutes, $function = 'put') | |
return $default; | ||
} | ||
|
||
/** | ||
* Write an item to the cache for indefinite-term storage. | ||
* | ||
* @param $key | ||
* @param $value | ||
* | ||
* @return mixed Depends on implementation | ||
*/ | ||
abstract public function forever($key, $value); | ||
|
||
/** | ||
* Get an item from the cache, or cache the default value forever. | ||
* | ||
|
@@ -123,14 +179,26 @@ public function sear($key, $default) | |
*/ | ||
abstract public function forget($key); | ||
|
||
/** | ||
* Delete an item from the cache. | ||
* | ||
* Enables you to use: unset($storage[$key]); | ||
* | ||
* @param string $key | ||
*/ | ||
public function offsetUnset($key) | ||
{ | ||
$this->forget($key); | ||
} | ||
|
||
/** | ||
* Get the expiration time as a UNIX timestamp. | ||
* | ||
* @param int $minutes | ||
* | ||
* @return int | ||
*/ | ||
protected function expiration($minutes) | ||
protected static function expiration($minutes) | ||
{ | ||
return time() + ($minutes * 60); | ||
} | ||
|