Hi All,

I am trying to use caches for storing temporary data that I want to
expire after some time.
I don't fully understand how the beaker caching works - if I create a
cache that I connect to a users session using the value stored in a
session key (say 'mycachekey') and create the cache with
code like this (there is a race condition in the cache creation, - two
users could potentially get the same random string in extreme cases -
not sure quite how to do this yet):

def check_key_in_cache(key):
    """ Checks if a key with a certain name exists in the cache"""
    for k in cache.caches.keys():
        if k.startswith(key):
            return True
    return False

""" Creates the random cache """
import random
rand = str(random.randomint())
while check_key_in_cache(rand):
    rand = random.randomint()
registrationcache =  cache.get_cache(rand, type='memory',
expiretime=6000)
session['mycachekey'] = rand
session.save()

The user does not have a login or unique id that I could use otherwise
at this stage.
Essentially, I want to avoid having to create entries in a database
for this, and then having a cronjob clean out old data.

I want the cache to 'clean itself' after some time, while maintaining
unique caches for each user for some amount of time.

Is this a reasonable approach?  Is there a way to delete a cache (not
just clear it)?

How does the expiretime work?

I couldn't figure it out from the documentation available
unfortunately.

The above may be used in a multi-page registration where I do not want
users being able to tamper with things in the session.  I'm guessing
another option woud be to encrypt the bits of the session I don't want
the user messing with, and achieve a similar result.

How do people deal with this kind of situation?

Alternatively is there a way of validating the session using
formencode?

The above is probably a serious misuse of the cache - but curiosity
got the better of me.

Thanks!
Damian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to