Hi,
When I first read too fast the TTL feature of the flush, I didn’t
understand it as it actually is but as something that could be a nice
feature.
The main idea is to flush the cache in a smooth way: i.e. you ensure
that after this flush operation, no data older than what you defined
is in the cache but you didn’t go through the empty cache step.
Basically, this can be done with a flush command that only flushes
data that are older than a given parameter.
In the end, you end up with a refreshed cache as with actual flush
feature but without having had to overload your backup DB. Of course,
DB shall support this traffic but this is always better to spare it!
To implement it with current API, this could be done giving a negative
TTL to the existing flush command. Indeed, that’s basically what we
want to do: flush the items stored before the TTL, but this TTL lies
in the past.
At first glance, currently, (don’t hesitate to correct me if I am
wrong)
- negative TTL is considered as 0
- we don’t keep creation time of the objects (only access times)
- settings.oldest_live is not supposed to work (well, even not working
I could say) with value older than present time
So I added negative support, the creation time of the objects and a
dedicated setting oldest_creation.
Basically, this works the same as for standard TTL but with a
dedicated check within do_item_get_notedeleted on these newly created
values. So I guess the overhead is pretty minimal.
Associated possible changes are at the end of the post.
Do you think this feature is worth being added to memcached?
I think this is a pretty easy nice to have (provided I didn’t miss
anything else in the code, I am not yet familiar with the whole
package …)
Thx,
Jean-Charles
diff ./items.c ../../memcached-1.2.6/items.c
156a157
> it->creatime = current_time;
432a434
>
441a444,447
> if (it != NULL && settings.oldest_creation != 0 && it->creatime <=
> settings.oldest_creation) {
> do_item_unlink(it); /* MTSAFE - cache_lock held */
> it = NULL;
> }
diff ./memcached.c ../../memcached-1.2.6/memcached.c
174a175
> settings.oldest_creation = 0;
1858a1860,1863
>
> settings.oldest_live = 0;
> settings.oldest_creation = 0;
>
1860a1866,1867
> else if (exptime < 0)
> settings.oldest_creation = realtime(exptime) - 1;
1862a1870
>
diff ./memcached.h ../../memcached-1.2.6/memcached.h
89a90
> rel_time_t oldest_creation; /* ignore existing items whose creation time
> is older than this */
115a117
> rel_time_t creatime; /* creation time */