Skip to content

Commit

Permalink
- Fixed behavior such that 'return' in 'ns_cache eval' works like des…
Browse files Browse the repository at this point in the history
…cribed in the documentation and in the old nscache module.

- Added documentation of optional 'pattern' argument for 'ns_cache names'.
  • Loading branch information
gneumann committed Jan 31, 2009
1 parent 671b7da commit 9fb1d64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 5 additions & 3 deletions doc/ns_cache.n
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'\" version of this file under either the License or the GPL.
'\"
'\"
'\" $Header: /Users/dossy/Desktop/cvs/aolserver/doc/ns_cache.n,v 1.5 2006/04/13 19:05:43 jgdavidson Exp $
'\" $Header: /Users/dossy/Desktop/cvs/aolserver/doc/ns_cache.n,v 1.6 2009/01/31 21:35:08 gneumann Exp $
'\"
'\"
'\" transliterated from index.html by [email protected] 2002-11-10
Expand All @@ -49,7 +49,7 @@ ns_cache \- Cache arbitrary data
\fBns_cache get \fIcachename key \fR?\fIvarname\fR?
\fBns_cache incr \fIcachename key ?value?\fR
\fBns_cache lappend \fIcachename key string ?string ...?\fR
\fBns_cache names \fIcachename\fR
\fBns_cache names \fIcachename ?pattern?\fR
\fBns_cache set \fIcachename key string\fR
.fi
.BE
Expand Down Expand Up @@ -118,8 +118,10 @@ if the key is missing an error is raised. If \fIvarname\fR is
provided and the key exists the command sets \fIvarname\fR to the
value and returns 1, otherwise it returns 0.
.TP
\fBns_cache names \fIcachename\fR
\fBns_cache names \fIcachename ?pattern?\fR
This command returns a list of all keys currently in the specified cache.
If \fIpattern\fR is specified, only matching entries are returned
(match pattern syntax like in \fBstring match\fR).

If the cache is thread-private, then the list only includes keys that
are in the thread's private cache.
Expand Down
17 changes: 12 additions & 5 deletions nsd/tclcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* Tcl API for cache.c. Based on work from the nscache module.
*/

static const char *RCSID = "@(#) $Header: /Users/dossy/Desktop/cvs/aolserver/nsd/tclcache.c,v 1.2 2005/08/01 20:29:24 jgdavidson Exp $, compiled: " __DATE__ " " __TIME__;
static const char *RCSID = "@(#) $Header: /Users/dossy/Desktop/cvs/aolserver/nsd/tclcache.c,v 1.3 2009/01/31 21:35:08 gneumann Exp $, compiled: " __DATE__ " " __TIME__;

#include "nsd.h"

Expand Down Expand Up @@ -391,6 +391,7 @@ NsTclCacheObjCmd(ClientData arg, Tcl_Interp *interp, int objc, Tcl_Obj **objv)
Tcl_WrongNumArgs(interp, 3, objv, "key script");
return TCL_ERROR;
}
status = TCL_OK;
key = Tcl_GetString(objv[3]);
Ns_CacheLock(cachePtr->cache);
entry = Ns_CacheCreateEntry(cachePtr->cache, key, &new);
Expand Down Expand Up @@ -438,13 +439,17 @@ NsTclCacheObjCmd(ClientData arg, Tcl_Interp *interp, int objc, Tcl_Obj **objv)
status = Tcl_EvalObjEx(interp, objv[4], 0);
Ns_CacheLock(cachePtr->cache);
entry = Ns_CacheCreateEntry(cachePtr->cache, key, &new);
if (status != TCL_OK) {
Ns_CacheFlushEntry(entry);
err = 1;
} else {

if (status == TCL_OK || status == TCL_RETURN) {
objPtr = Tcl_GetObjResult(interp);
valPtr = NewVal(cachePtr, objPtr, &now);
Ns_CacheSetValueSz(entry, valPtr, valPtr->length);

if (status == TCL_RETURN) {
status = TCL_OK;
}
} else {
Ns_CacheFlushEntry(entry);
}
Ns_CacheBroadcast(cachePtr->cache);
}
Expand All @@ -453,6 +458,8 @@ NsTclCacheObjCmd(ClientData arg, Tcl_Interp *interp, int objc, Tcl_Obj **objv)
if (err) {
return TCL_ERROR;
}

return status;
break;
}
return TCL_OK;
Expand Down

0 comments on commit 9fb1d64

Please sign in to comment.