Advertisement
Guest User

flungabunga

a guest
Sep 20th, 2008
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2. class ExtendedMemcache extends Memcache
  3. {
  4.  
  5.     protected $hash = array();
  6.  
  7.     function __construct()
  8.     {}
  9.  
  10.     function getHash()
  11.     {
  12.         return $this->hash;
  13.     }
  14.    
  15.     function setHash($arrHash)
  16.     {
  17.         $this->hash = $arrHash;
  18.     }
  19.        
  20.     private function addGroupKeyAssoc($strGroup, $strKey)
  21.     {
  22.         $hash = $this->getHash();
  23.         $hash[$strGroup][] = $strKey;
  24.         $this->setHash($hash);
  25.     }
  26.  
  27.     function set ($strGroup, $strKey, $value)
  28.     {
  29.         $this->addGroupKeyAssoc($strGroup, $strKey);
  30.         parent::set($strKey, $value);
  31.     }
  32.  
  33.     function deleteGroup($strGroup)
  34.     {
  35.         $hash = $this->getHash();
  36.         $groupKeys = $hash[$strGroup];
  37.         if (is_array($groupKeys)) foreach ($groupKeys as $groupKey) {
  38.             $this->delete($groupKey);
  39.         }
  40.     }
  41. }
  42.  
  43. $memcache  = new ExentedMemcache();
  44. $memcache->set('thread123', 'posts.page5.offset10', $pagedPosts5);
  45. $memcache->set('thread123', 'posts.page6.offset10', $pagedPosts6);
  46. $memcache->set('thread123', 'posts.page7.offset11', $pagedPosts7);
  47. /// etc etc
  48.  
  49. /// then to delete everything for the thread.
  50. $memcache->deleteGroup('thread123');
  51.  
  52. /// w00t!
  53.  
  54.  
  55.  
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement