refreshing the cache time of a key
Oleksandr V. Typlyns'kyi
astral at sputnikmedia.net
Wed Feb 27 21:10:12 UTC 2008
Today Feb 27, 2008 at 09:51 Dustin Sallings wrote:
>
> On Feb 27, 2008, at 4:17, bharath venkatesh wrote:
>
> > is it possible to refresh the cache time of a key with out having to
> > retrieving the cached data and storing it back in memcache .. for example if
> > a data is cached for
> > 1 hour and at the 50th minute from the time this data has been cached i
> > want to store it in the cache for 1 more hour ..is there a function
> > to refresh the cache time by knowing the key of data with out having to do
> > get and set
>
>
> There's been talk of a ``touch'' command, but no work has been done on implementing such a thing.
Maybe it can be simple based on incr/decr?
diff -rU 1 memcached.orig memcached.c
--- memcached.orig 2007-12-02 07:50:14.000000000 +0200
+++ memcached.c 2008-02-27 23:07:40.000000000 +0200
@@ -1507,2 +1507,50 @@
+static void process_touch_command(conn *c, token_t *tokens, const size_t ntokens) {
+ item *it;
+ char *key;
+ size_t nkey;
+ time_t exptime;
+
+ assert(c != NULL);
+
+ if(tokens[KEY_TOKEN].length > KEY_MAX_LENGTH) {
+ out_string(c, "CLIENT_ERROR bad command line format");
+ return;
+ }
+
+ key = tokens[KEY_TOKEN].value;
+ nkey = tokens[KEY_TOKEN].length;
+
+ if (settings.managed) {
+ int bucket = c->bucket;
+ if (bucket == -1) {
+ out_string(c, "CLIENT_ERROR no BG data in managed mode");
+ return;
+ }
+ c->bucket = -1;
+ if (buckets[bucket] != c->gen) {
+ out_string(c, "ERROR_NOT_OWNER");
+ return;
+ }
+ }
+
+ exptime = strtol(tokens[2].value, NULL, 10);
+
+ if(errno == ERANGE) {
+ out_string(c, "CLIENT_ERROR bad command line format");
+ return;
+ }
+
+ it = item_get(key, nkey);
+
+ if (it) {
+ it->exptime=realtime(exptime);
+ do_item_update(it);
+ out_string(c, "STORED");
+ item_remove(it); /* release our reference */
+ } else {
+ out_string(c, "NOT_FOUND");
+ }
+}
+
static void process_delete_command(conn *c, token_t *tokens, const size_t ntokens) {
@@ -1661,2 +1709,6 @@
+ } else if (ntokens == 4 && (strcmp(tokens[COMMAND_TOKEN].value, "touch") == 0)) {
+
+ process_touch_command(c, tokens, ntokens);
+
} else if (ntokens >= 3 && ntokens <= 4 && (strcmp(tokens[COMMAND_TOKEN].value, "delete") == 0)) {
--
WNGS-RIPE
KP Media / bigmir)net
More information about the memcached
mailing list