Hello everyone
I have this Two Methods
private function cacheAdd($id,$data)
{
$this->minicache->set($id,$data);
}
private function cacheGet($id)
{
return $this->minicache->get($id);
}
Each time if i want to check if the items are cached i have to do something like that:
public function getFriendIds()
{
$info = $this->cache->minicache->getInfo("getFriendIds"); // if its an array then it is cached
if(is_array($info))
{
return $this->cache->cacheGet("getFriendIds"); // return the cached object
}
// from here items wasnt cached
else
{
$this->cache->cacheAdd("getFriendIds",$this->twitter->getFriendIds()); // so add to cache
return $this->cache->cacheGet("getFriendIds"); // and return the cached items
}
}
But i think there is a simple method to do this right?
I thought something like this:
$this->cache->docache($this->myitems());
and method docache takes just the method and converts the methodname to string and checks if the item is already cached or not How could that be done?
EDIT:
I implemented this docache method
public function docache($id,$data)
{
$info = $this->minicache->getInfo($id);
if(is_array($info))
{
return $this->cache->cacheGet($id); // return the cached object
}
else
{
$this->cacheAdd($id,$data); // so add to cache
return $this->cacheGet($id); // and return the cached items
}
}
and if i want to call the method i do this.
public function getFriendIds()
{
return $this->cache->docache("getFriendIds",$this->twitter->getFriendIds());
}
No this is much smaller isnt it?