ported psgi and rack plugin to the new caching api

This commit is contained in:
Unbit
2013-01-23 20:32:52 +01:00
parent b90779aecf
commit e839a9eb89
3 changed files with 26 additions and 17 deletions
+9
View File
@@ -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);
+5 -5
View File
@@ -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);
+12 -12
View File
@@ -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;
}