From: Stephen D. <sd...@gm...> - 2006-04-05 19:33:27
|
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 <ser...@us...> 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 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > 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 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > 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 expire= d yet > + * > + * Results: > + * TCL result with entry value or empty result > + * > + * Side effects: > + * None. > + * > + *---------------------------------------------------------------------= - > + */ > + > + int > + NsTclCacheGetObjCmd(ClientData arg, Tcl_Interp *interp, int objc, Tcl_O= bj *CONST objv[]) > + { > + Ns_Cache *cache; > + Ns_Entry *entry; > + char *key; > + > + Ns_ObjvSpec args[] =3D { > + {"cache", ObjvCache, &cache, arg}, > + {"key", Ns_ObjvString, &key, NULL}, > + {NULL, NULL, NULL, NULL} > + }; > + if (Ns_ParseObjv(NULL, args, interp, 1, objc, objv) !=3D NS_OK) { > + return TCL_ERROR; > + } > + Ns_CacheLock(cache); > + if ((entry =3D Ns_CacheFindEntry(cache, key)) !=3D 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_O= bj *CONST objv[]) > + { > + NsInterp *itPtr =3D arg; > + Ns_Cache *cache; > + Ns_Entry *entry; > + char *key, *value =3D 0; > + int new, timeout =3D -1, ttl =3D 0; > + > + Ns_ObjvSpec opts[] =3D { > + {"-timeout", Ns_ObjvInt, &timeout, NULL}, > + {"-ttl", Ns_ObjvInt, &ttl, NULL}, > + {"--", Ns_ObjvBreak, NULL, NULL}, > + {NULL, NULL, NULL, NULL} > + }; > + Ns_ObjvSpec args[] =3D { > + {"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) !=3D NS_OK) { > + return TCL_ERROR; > + } > + if ((entry =3D CreateEntry(itPtr, cache, key, &new, timeout)) =3D= =3D 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 langua= ge > that extends applications into web and mobile media. Attend the live webc= ast > and join the prime developer group breaking into this new coding territor= y! > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D110944&bid=3D241720&dat= =3D121642 > _______________________________________________ > naviserver-commits mailing list > nav...@li... > https://lists.sourceforge.net/lists/listinfo/naviserver-commits > |