-
Notifications
You must be signed in to change notification settings - Fork 7
Allow seamless storage of arrays and objects within IronCache. #7
Copy link
Copy link
Open
Description
I'm not sure if this is out of scope for this project or not, but it might be handy to allow storage and retrieval of arrays and objects. The following code snippet extends IronCache to add this functionality, however there are a few limitations:
- Storing strings that are valid serial objects/arrays would come out as an array or object.
- The detection for a serialised variable is a bit dirty.
Perhaps this should only exist as a subclass that can be used as necessary or maybe the methods should be refactored into "putSerialized" and "getSerialized".
class FlexIronCache extends IronCache {
public function put($key, $item){
if (is_array($item) || is_object($item)) {
$item = serialize($item);
}
return $this->putItem($this->cache_name, $key, $item);
}
public function get($key){
$val = $this->getItem($this->cache_name, $key);
$unserialised = @unserialize($val->value);
if ($unserialised !== FALSE) {
$val->value = $unserialised;
}
return $val;
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels