Horde::SessionCache->deleteObject function...

René Lund Jensen lundeman@tbkol.dk
Sat, 15 Dec 2001 03:39:13 +0100


Hey there..

I really could use a function like the above...

The problem is, I'm really not good at this diff stuff.
So I'll just write my code directly in the mail...
I'm still unsure about scope when writing PHP,
so it might need some editing...

function deleteObject($objectID){
    $store = Horde::SessionCache->getObject($objectID);
    if (!$store)
    {
        return false;
    }
    $GLOBALS['hordeObjectCache'] =
&$GLOBALS['HTTP_SESSION_VARS']['hordeObjectCache'];
    $tmp = $GLOBALS['hordeObjectCache'];
    unset($GLOBALS['hordeObjectCache']);
    global $hordeObjectCache;
    $hordeObjectCache = array();
    while(list($key, $val) = each($tmp)){
        if($key != $objectID){
            $hordeObjectCache[$key] = $val;
        }
    }
    $GLOBALS['HTTP_SESSION_VARS']['hordeObjectCache'] = &$hordeObjectCache;
    return $store;
}
(mind linewraps)

This is mainly copy/paste from the other two functions in
Horde::SessionCache,
and maybe there is a faster, and more "clean" way of doing this. I just
can't find that array_purge() function in PHP :o)

The reason for this function is that I have one object that I want to keep
in my cache, but I fear that it will die the "prune"-death..
With this function it's possible to clear the cache for unwanted objects,
while keeping the important ones...

I hope I'm not the only one who can use this, so that it can make it into
the Horde code...

Let me know what you think of this...

René Jensen
lundeman@tbkol.dk