diff options
-rw-r--r-- | include/urweb/types_cpp.h | 1 | ||||
-rw-r--r-- | include/urweb/urweb_cpp.h | 6 | ||||
-rw-r--r-- | src/c/urweb.c | 11 | ||||
-rw-r--r-- | src/lru_cache.sml | 11 |
4 files changed, 16 insertions, 13 deletions
diff --git a/include/urweb/types_cpp.h b/include/urweb/types_cpp.h index 4847a3fd..3955dcc8 100644 --- a/include/urweb/types_cpp.h +++ b/include/urweb/types_cpp.h @@ -140,6 +140,7 @@ typedef struct uw_Sqlcache_Cache { struct uw_Sqlcache_Entry *table; unsigned long timeInvalid; unsigned long timeNow; + size_t numKeys; UT_hash_handle hh; } uw_Sqlcache_Cache; diff --git a/include/urweb/urweb_cpp.h b/include/urweb/urweb_cpp.h index f89c432c..15bfffac 100644 --- a/include/urweb/urweb_cpp.h +++ b/include/urweb/urweb_cpp.h @@ -406,8 +406,8 @@ void uw_Basis_writec(struct uw_context *, char); // Sqlcache. -uw_Sqlcache_Value *uw_Sqlcache_check(uw_Sqlcache_Cache *, char **, int); -void *uw_Sqlcache_store(uw_Sqlcache_Cache *, char **, int, uw_Sqlcache_Value *); -void *uw_Sqlcache_flush(uw_Sqlcache_Cache *, char **, int); +uw_Sqlcache_Value *uw_Sqlcache_check(uw_Sqlcache_Cache *, char **); +void *uw_Sqlcache_store(uw_Sqlcache_Cache *, char **, uw_Sqlcache_Value *); +void *uw_Sqlcache_flush(uw_Sqlcache_Cache *, char **); #endif diff --git a/src/c/urweb.c b/src/c/urweb.c index 30619314..71130cc7 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -488,7 +488,7 @@ struct uw_context { char *output_buffer; size_t output_buffer_size; - // For caching. + // Sqlcache. int numRecording; int recordingOffset; @@ -4616,7 +4616,8 @@ char *uw_Sqlcache_keyCopy(char *buf, char *key) { // The NUL-terminated prefix of [key] below always looks something like "_k1_k2_k3..._kn". // TODO: strlen(key) = buf - key? -uw_Sqlcache_Value *uw_Sqlcache_check(uw_Sqlcache_Cache *cache, char **keys, int numKeys) { +uw_Sqlcache_Value *uw_Sqlcache_check(uw_Sqlcache_Cache *cache, char **keys) { + size_t numKeys = cache->numKeys; char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); char *buf = key; time_t timeInvalid = cache->timeInvalid; @@ -4636,7 +4637,8 @@ uw_Sqlcache_Value *uw_Sqlcache_check(uw_Sqlcache_Cache *cache, char **keys, int return value && value->timeValid > timeInvalid ? value : NULL; } -void uw_Sqlcache_store(uw_Sqlcache_Cache *cache, char **keys, int numKeys, uw_Sqlcache_Value *value) { +void uw_Sqlcache_store(uw_Sqlcache_Cache *cache, char **keys, uw_Sqlcache_Value *value) { + size_t numKeys = cache->numKeys; char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); char *buf = key; time_t timeNow = uw_Sqlcache_getTimeNow(cache); @@ -4659,7 +4661,8 @@ void uw_Sqlcache_store(uw_Sqlcache_Cache *cache, char **keys, int numKeys, uw_Sq entry->value->timeValid = timeNow; } -void uw_Sqlcache_flush(uw_Sqlcache_Cache *cache, char **keys, int numKeys) { +void uw_Sqlcache_flush(uw_Sqlcache_Cache *cache, char **keys) { + size_t numKeys = cache->numKeys; char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); char *buf = key; time_t timeNow = uw_Sqlcache_getTimeNow(cache); diff --git a/src/lru_cache.sml b/src/lru_cache.sml index 6fcfdc55..d4da2849 100644 --- a/src/lru_cache.sml +++ b/src/lru_cache.sml @@ -62,14 +62,14 @@ fun setupQuery {index, params} = val revArgs = paramRepeatRev (fn p => "p" ^ p) ", " - val numArgs = Int.toString params - in Print.box [string ("static uw_Sqlcache_Cache cacheStruct" ^ i ^ " = {"), newline, string " .table = NULL,", newline, + string (" .numKeys = " ^ Int.toString params ^ ","), + newline, string " .timeInvalid = 0,", newline, string " .timeNow = 0};", @@ -83,8 +83,7 @@ fun setupQuery {index, params} = newline, string (" char *ks[] = {" ^ revArgs ^ "};"), newline, - string " uw_Sqlcache_Value *v = ", - string ("uw_Sqlcache_check(cache" ^ i ^ ", ks, " ^ numArgs ^ ");"), + string (" uw_Sqlcache_Value *v = uw_Sqlcache_check(cache" ^ i ^ ", ks);"), newline, (* If the output is null, it means we had too much recursion, so it's a miss. *) string " if (v && v->output != NULL) {", @@ -122,7 +121,7 @@ fun setupQuery {index, params} = newline, string (" puts(\"SQLCACHE: stored " ^ i ^ ".\");"), newline, - string (" uw_Sqlcache_store(cache" ^ i ^ ", ks, " ^ numArgs ^ ", v);"), + string (" uw_Sqlcache_store(cache" ^ i ^ ", ks, v);"), newline, string " return uw_unit_v;", newline, @@ -135,7 +134,7 @@ fun setupQuery {index, params} = newline, string (" char *ks[] = {" ^ revArgs ^ "};"), newline, - string (" uw_Sqlcache_flush(cache" ^ i ^ ", ks, " ^ numArgs ^ ");"), + string (" uw_Sqlcache_flush(cache" ^ i ^ ", ks);"), newline, string " return uw_unit_v;", newline, |