python-stdnet icon indicating copy to clipboard operation
python-stdnet copied to clipboard

Expiring objects in python-stdnet?

Open SamuelMarks opened this issue 12 years ago • 8 comments

One of the main reasons for me to use Redis is as a cache; so it is very important that I can insert keys with specify expires (using Redis; not my own custom expires_in member).

How do I expire keys in python-stdnet?

SamuelMarks avatar Jan 23 '14 05:01 SamuelMarks

In my exploring, I can't find such feature. I think Stdnet doesn't support it. Because, Stdnet intends to support multi-backend which may not support expiring entry.

For now, manual deleting (by creation/update datetime) using model is only way. I think this is only way for consistency.

jbking avatar Sep 16 '14 07:09 jbking

Many NoSQL stores support this feature, for those that don't you can handle it manually (e.g.: push a timestamp on each expirable record, on get requests check if it's still valid before returning to requester, if expired delete from db)

SamuelMarks avatar Sep 16 '14 09:09 SamuelMarks

stdnet is a data mapper, one instance of a model can have several keys associated with it. For example, in redis an object has a key for the hash, a key for every index (either sets or zset) and few others for internal use. In this respect, it doesn't make lots of sense talking about expiring keys in stdnet, expiring objects could be the equivalent. Such feature is not available, if you need to expire them you can do it programmatically by deleting them.

If you are using redis as a cache, why do you need the object data mapping of stdnet? Do you want to expire keys or objects? Can you share your use case?

lsbardel avatar Sep 17 '14 06:09 lsbardel

I thought also the feature before. A case is making an ephemeral odm object by TTL. In redis, automatic expiring redis object is supported natively, and it prevents code bugs which related to deleting. But in stdnet, such object may break system data structure.

By writing above, I got an idea. Let me explain.

  1. introduce a field for TTL, called "_ttl" here.
  2. if a odm object specified as ephemeral object and related backend supports it, set correspond TTL value for the field in Hash.
  3. in retrieving the object in Lua script, returns none if the TTL is over.
  4. also delete the object in stdnet.

How about this? We can do the step 1, but step 2-4 needs stdnet support.

jbking avatar Sep 17 '14 09:09 jbking

Sounds interesting but I don't need this feature and I don't have time at the moment. Happy to assist if anyone decides to implement it.

lsbardel avatar Sep 17 '14 21:09 lsbardel

OK, but which branch is better for development? Branch dev seems broken by ci..

jbking avatar Sep 18 '14 03:09 jbking

I would create a new branch from master

lsbardel avatar Sep 19 '14 07:09 lsbardel

@lsbardel I've made an issue #81 as another topic

jbking avatar Sep 20 '14 06:09 jbking