Built in caching for primary key queries
Selects done against a primary key will automatically cache to Memcached (haven't tried it, but it should fail gracefully) indexed by the model name and the primary key ([NAMESPACE-]MODEL-PKEY). Any updates or deletes against the same primary key will purge the cache automatically. The major caveat here is the case of mass updates which would result in stale data. As it stands the data is being cached for a mere 5 minutes, so this multiple row update scenario would be short lived but ideally, I'll be pushing back the time to live on the cache and/or making it something that's configurable. If you have to do mass updates, you're probably doing them with a cronjob and should just be flushing all of the cache in that scenario (as it would be nearly impossible to detect the affected keys and purge them all).
This commit is contained in:
parent
dc0d98906f
commit
99aa78b6fa
3 changed files with 110 additions and 84 deletions
|
@ -24,7 +24,9 @@
|
|||
* don't entirely remember specifics, but the reason for not using Memcached()
|
||||
* was due to an unexplainable bug in the version in the repository for Ubuntu
|
||||
* 10.04 LTS. Memcached() does support more of the memcached protocol and will
|
||||
* eventually be what PICKLES uses.
|
||||
* eventually be what PICKLES uses. Keys are forced to be uppercase for
|
||||
* consistencies sake as I've been burned by the case sensitivity due to typos
|
||||
* in my code.
|
||||
*
|
||||
* Requires php5-memcache
|
||||
*
|
||||
|
@ -155,7 +157,7 @@ class Cache extends Object
|
|||
{
|
||||
if ($this->open())
|
||||
{
|
||||
return $this->connection->get($this->namespace . $key);
|
||||
return $this->connection->get(strtoupper($this->namespace . $key));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -177,9 +179,11 @@ class Cache extends Object
|
|||
*/
|
||||
public function set($key, $value, $expire = 300)
|
||||
{
|
||||
$key = strtoupper($key);
|
||||
|
||||
if ($this->open())
|
||||
{
|
||||
return $this->connection->set($this->namespace . $key, $value, 0, $expire);
|
||||
return $this->connection->set(strtoupper($this->namespace . $key), $value, 0, $expire);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -197,7 +201,7 @@ class Cache extends Object
|
|||
{
|
||||
if ($this->open())
|
||||
{
|
||||
return $this->connection->delete($this->namespace . $key);
|
||||
return $this->connection->delete(strtoupper($this->namespace . $key));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -216,7 +220,7 @@ class Cache extends Object
|
|||
{
|
||||
if ($this->open())
|
||||
{
|
||||
return $this->connection->increment($this->namespace . $key);
|
||||
return $this->connection->increment(strtoupper($this->namespace . $key));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue