Yes, i use cache and in my case i do need to use get and set in different situations, for example i need to set cache entry regardless of what is there, eval will return me existing value, so i need to flush it first which gets to the same race condition issue. Same with get, i just need to get value if it exists without issuing exists first and then eval, if it is not there i do not want to set it, eval will set it.

Stephen Deasey wrote:
What's the use case for these commands?  I looked at the existing
usage in e.g. ACS back when I added this and it seems that people are
calling _get, and if it's not there, then calling _set.  But this
looks like a race condition to me.

Does _eval not cover everything?



On 4/5/06, Vlad Seryakov <[EMAIL PROTECTED]> wrote:
Update of /cvsroot/naviserver/naviserver/nsd
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24426/nsd

Modified Files:
       tclcache.c tclcmds.c
Log Message:
Added 2 new cache commands ns_cache_get and ns_cache_set for easier cache 
manipulation


Index: tclcmds.c
===================================================================
RCS file: /cvsroot/naviserver/naviserver/nsd/tclcmds.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** tclcmds.c   28 Feb 2006 20:02:37 -0000      1.34
--- tclcmds.c   5 Apr 2006 17:52:31 -0000       1.35
***************
*** 73,76 ****
--- 73,78 ----
     NsTclCacheCreateObjCmd,
     NsTclCacheEvalObjCmd,
+     NsTclCacheGetObjCmd,
+     NsTclCacheSetObjCmd,
     NsTclCacheFlushObjCmd,
     NsTclCacheIncrObjCmd,
***************
*** 259,262 ****
--- 261,266 ----
     {"ns_cache_create", NULL, NsTclCacheCreateObjCmd},
     {"ns_cache_eval", NULL, NsTclCacheEvalObjCmd},
+     {"ns_cache_get", NULL, NsTclCacheGetObjCmd},
+     {"ns_cache_set", NULL, NsTclCacheSetObjCmd},
     {"ns_cache_flush", NULL, NsTclCacheFlushObjCmd},
     {"ns_cache_incr", NULL, NsTclCacheIncrObjCmd},

Index: tclcache.c
===================================================================
RCS file: /cvsroot/naviserver/naviserver/nsd/tclcache.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** tclcache.c  23 Jan 2006 15:57:33 -0000      1.2
--- tclcache.c  5 Apr 2006 17:52:31 -0000       1.3
***************
*** 285,288 ****
--- 285,378 ----
 }

+ /*
+  *----------------------------------------------------------------------
+  *
+  * NsTclCacheGetObjCmd --
+  *
+  *      Returns entry value if entry exists in the cache and not expired yet
+  *
+  * Results:
+  *      TCL result with entry value or empty result
+  *
+  * Side effects:
+  *      None.
+  *
+  *----------------------------------------------------------------------
+  */
+
+ int
+ NsTclCacheGetObjCmd(ClientData arg, Tcl_Interp *interp, int objc, Tcl_Obj 
*CONST objv[])
+ {
+     Ns_Cache *cache;
+     Ns_Entry *entry;
+     char     *key;
+
+     Ns_ObjvSpec args[] = {
+         {"cache",    ObjvCache,     &cache, arg},
+         {"key",      Ns_ObjvString, &key,   NULL},
+         {NULL, NULL, NULL, NULL}
+     };
+     if (Ns_ParseObjv(NULL, args, interp, 1, objc, objv) != NS_OK) {
+         return TCL_ERROR;
+     }
+     Ns_CacheLock(cache);
+     if ((entry = Ns_CacheFindEntry(cache, key)) != NULL) {
+         Tcl_SetStringObj(Tcl_GetObjResult(interp),
+                          Ns_CacheGetValue(entry), Ns_CacheGetSize(entry));
+     }
+     Ns_CacheUnlock(cache);
+     return TCL_OK;
+ }
+
+ /*
+  *----------------------------------------------------------------------
+  *
+  * NsTclCacheSetObjCmd --
+  *
+  *      Set new value of the cache entry
+  *
+  * Results:
+  *      TCL result.
+  *
+  * Side effects:
+  *      None.
+  *
+  *----------------------------------------------------------------------
+  */
+
+ int
+ NsTclCacheSetObjCmd(ClientData arg, Tcl_Interp *interp, int objc, Tcl_Obj 
*CONST objv[])
+ {
+     NsInterp *itPtr = arg;
+     Ns_Cache *cache;
+     Ns_Entry *entry;
+     char     *key, *value = 0;
+     int       new, timeout = -1, ttl = 0;
+
+     Ns_ObjvSpec opts[] = {
+         {"-timeout", Ns_ObjvInt,   &timeout, NULL},
+         {"-ttl",     Ns_ObjvInt,   &ttl,     NULL},
+         {"--",       Ns_ObjvBreak, NULL,     NULL},
+         {NULL, NULL, NULL, NULL}
+     };
+     Ns_ObjvSpec args[] = {
+         {"cache",    ObjvCache,     &cache, arg},
+         {"key",      Ns_ObjvString, &key,   NULL},
+         {"value",    Ns_ObjvString, &value, NULL},
+         {NULL, NULL, NULL, NULL}
+     };
+     if (Ns_ParseObjv(opts, args, interp, 1, objc, objv) != NS_OK) {
+         return TCL_ERROR;
+     }
+     if ((entry = CreateEntry(itPtr, cache, key, &new, timeout)) == NULL) {
+         return TCL_ERROR;
+     }
+     Tcl_SetStringObj(Tcl_GetObjResult(interp), value, -1);
+     SetEntry(interp, entry, NULL, ttl);
+     Ns_CacheUnlock(cache);
+
+     return TCL_OK;
+ }
+

 /*



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
naviserver-commits mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/naviserver-commits



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642
_______________________________________________
naviserver-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/naviserver-devel


--
Vlad Seryakov
571 262-8608 office
[EMAIL PROTECTED]
http://www.crystalballinc.com/vlad/


Reply via email to