tidwall / buntdb

BuntDB is an embeddable, in-memory key/value database for Go with custom indexing and geospatial support
MIT License
4.57k stars 289 forks source link

data expiration #11

Closed imikod closed 8 years ago

imikod commented 8 years ago

It seems like the expiration only works as long as the program does not exit before the expiration.

If I set a key to expire in 10 seconds and the program finishes in 5 I can run it as many times as I want without the expiration ever happening. Is this intentional?

tidwall commented 8 years ago

Yes, this is by design. It's not ideal and I've debated using a timestamp rather than a TTL duration, but ran into other issues with the timestamp. So I ended up settling on using a duration, which mimics the functionality of Redis's TTLs. And Redis also suffers from the same issue.

I have an idea though. I think I'll explore it and get back to you shortly.

tidwall commented 8 years ago

I just added a feature that will compare the ttl against the database mod time at load.

if noKeyTTL || (keyTTL-time.Now().Sub(dbLastModTime) > 0) {
    ... load the key into the database ...
}

I think that this will suffice for the majority of cases.
Let me know if this works for you.

imikod commented 8 years ago

Yes thank you that works for me! For redis or redcon it isn't a big deal but for embedded use it's somewhat different.

tidwall commented 8 years ago

Great to hear. Thanks a ton for your help.