0

i want to cache my object in the memory for performance,but also need to recycle them if it's too long not accessed.

every 30 minutes a function would be called , check every cache object , like a file's attributes in windows operation system, each object should have two attributes:last modified time stamp(or a flag) and last accessed time stamp, if the last modified time is great than zero, create a sql for update them in datebase ,and reset the modified time to 0, if the last accessed time is larger than 30 minutes, then delete them from the cache system.

What is the best way to implement them?and is there already a similar system in python so i don't have to reinvent the wheel.

ps. no Memcached. the object should be accessed directly, no serialization and deserialization .

4

1 回答 1

1

Either you create a class with these attributes as attributes, or you just use a dictionary. It's a matter of taste, both works. Having a class gives you the possibility to also make methods like "is_old" or "is_modified" etc.

The same goes for the structure to hold all the data. It's basically a giant dictionary, but you might want to wrap it in a class with methods like "purge_old" etc.

于 2012-11-02T08:11:07.123 回答