From e839a9eb89447b65b6b5efd3035abf98e4e1d060 Mon Sep 17 00:00:00 2001 From: Unbit Date: Wed, 23 Jan 2013 20:32:52 +0100 Subject: [PATCH] ported psgi and rack plugin to the new caching api --- core/cache.c | 9 +++++++++ plugins/psgi/uwsgi_plmodule.c | 10 +++++----- plugins/rack/rack_api.c | 24 ++++++++++++------------ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/core/cache.c b/core/cache.c index bf3d147d..00df126a 100644 --- a/core/cache.c +++ b/core/cache.c @@ -853,8 +853,17 @@ void uwsgi_cache_create(char *arg) { uc->keysize = 2048; uc->hashsize = UMAX16; uc->hash = uwsgi_hash_algo_get("djb33x"); + uc->store = uwsgi.cache_store; } else { + char *c_name = NULL; + char *c_max_items = NULL; + char *c_blocksize = NULL; + char *c_blocks = NULL; + char *c_hash = NULL; + char *c_hashsize = NULL; + char *c_store = NULL; + char *c_name = NULL; } uwsgi_cache_init(uc); diff --git a/plugins/psgi/uwsgi_plmodule.c b/plugins/psgi/uwsgi_plmodule.c index fc9904ed..f3997cfa 100644 --- a/plugins/psgi/uwsgi_plmodule.c +++ b/plugins/psgi/uwsgi_plmodule.c @@ -114,9 +114,9 @@ XS(XS_cache_set) { key = SvPV(ST(0), keylen); val = SvPV(ST(1), vallen); - uwsgi_wlock(uwsgi.cache_lock); + uwsgi_wlock(uwsgi.caches->lock); uwsgi_cache_set(key, (uint16_t) keylen, val, (uint64_t) vallen, 0, 0); - uwsgi_rwunlock(uwsgi.cache_lock); + uwsgi_rwunlock(uwsgi.caches->lock); clear: XSRETURN_UNDEF; @@ -135,16 +135,16 @@ XS(XS_cache_get) { key = SvPV(ST(0), keylen); - uwsgi_rlock(uwsgi.cache_lock); + uwsgi_rlock(uwsgi.caches->lock); val = uwsgi_cache_get(key, (uint16_t) keylen, &vallen); if (!val) - uwsgi_rwunlock(uwsgi.cache_lock); + uwsgi_rwunlock(uwsgi.caches->lock); clear: XSRETURN_UNDEF; ST(0) = newSVpv(val, vallen); - uwsgi_rwunlock(uwsgi.cache_lock); + uwsgi_rwunlock(uwsgi.caches->lock); sv_2mortal(ST(0)); XSRETURN(1); diff --git a/plugins/rack/rack_api.c b/plugins/rack/rack_api.c index cf92280a..721b5bbd 100644 --- a/plugins/rack/rack_api.c +++ b/plugins/rack/rack_api.c @@ -289,13 +289,13 @@ VALUE rack_uwsgi_cache_set(VALUE *class, VALUE rbkey, VALUE rbvalue) { return Qnil; } - uwsgi_wlock(uwsgi.cache_lock); + uwsgi_wlock(uwsgi.caches->lock); if (uwsgi_cache_set(key, keylen, value, vallen, expires, 0)) { - uwsgi_rwunlock(uwsgi.cache_lock); + uwsgi_rwunlock(uwsgi.caches->lock); return Qnil; } - uwsgi_rwunlock(uwsgi.cache_lock); + uwsgi_rwunlock(uwsgi.caches->lock); return Qtrue; } @@ -317,13 +317,13 @@ VALUE rack_uwsgi_cache_update(VALUE *class, VALUE rbkey, VALUE rbvalue) { return Qnil; } - uwsgi_wlock(uwsgi.cache_lock); + uwsgi_wlock(uwsgi.caches->lock); if (uwsgi_cache_set(key, keylen, value, vallen, expires, UWSGI_CACHE_FLAG_UPDATE)) { - uwsgi_rwunlock(uwsgi.cache_lock); + uwsgi_rwunlock(uwsgi.caches->lock); return Qnil; } - uwsgi_rwunlock(uwsgi.cache_lock); + uwsgi_rwunlock(uwsgi.caches->lock); return Qtrue; } @@ -357,13 +357,13 @@ VALUE rack_uwsgi_cache_del(VALUE *class, VALUE rbkey) { char *key = RSTRING_PTR(rbkey); size_t keylen = RSTRING_LEN(rbkey); - uwsgi_wlock(uwsgi.cache_lock); + uwsgi_wlock(uwsgi.caches->lock); if (uwsgi_cache_del(key, keylen, 0, 0)) { - uwsgi_rwunlock(uwsgi.cache_lock); + uwsgi_rwunlock(uwsgi.caches->lock); return Qfalse; } - uwsgi_rwunlock(uwsgi.cache_lock); + uwsgi_rwunlock(uwsgi.caches->lock); return Qtrue; } @@ -395,14 +395,14 @@ VALUE rack_uwsgi_cache_get(VALUE *class, VALUE rbkey) { uint64_t valsize; char *value = NULL; - uwsgi_rlock(uwsgi.cache_lock); + uwsgi_rlock(uwsgi.caches->lock); value = uwsgi_cache_get(key, keylen, &valsize); if (!value) { - uwsgi_rwunlock(uwsgi.cache_lock); + uwsgi_rwunlock(uwsgi.caches->lock); return Qnil; } VALUE res = rb_str_new(value, valsize); - uwsgi_rwunlock(uwsgi.cache_lock); + uwsgi_rwunlock(uwsgi.caches->lock); return res; }