Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Update AntiDogPileMemcache.php
Browse files Browse the repository at this point in the history
Add "deleteAdp" function call as suggest in issue #10 by @andrzejdziekonski
  • Loading branch information
mevdschee committed Jan 30, 2016
1 parent 591ef2f commit b3cd78e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Cache/AntiDogPileMemcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,26 @@ public function setAdp($key, $value, $ttl=0)

return $result;
}

/**
* Function to delete value by key using Anti-Dog-Pile algorithm.
* NB: Use this function for cache invalidation under high load
*
* @param string $key Key of the value you are deleting
*
* @return boolean True on success, false on failure
*/
public function deleteAdp($key)
{
$value = $this->get($key);
if ($value===false) {
return false;
}
list($exp, $ttl, $val) = explode('|', $value, 3);
$time = time();
$value = implode('|', array($time-1, $ttl, $val));
$result = $this->set($key, $value);

return $result;
}
}

0 comments on commit b3cd78e

Please sign in to comment.