// get an item from the cache func CacheGet(key string) []byte { if int(C.uwsgi_cache_enabled()) == 0 { return nil } k := C.CString(key) defer C.free(unsafe.Pointer(k)) kl := len(key) var vl C.uint64_t = C.uint64_t(0) C.uwsgi_cache_rlock() c_value := C.uwsgi_cache_get(k, C.uint16_t(kl), &vl) var p []byte if vl > 0 { p = C.GoBytes((unsafe.Pointer)(c_value), C.int(vl)) } else { p = nil } C.uwsgi_cache_rwunlock() return p }
// check if an item exists in the cache func CacheExists(key string) bool { if int(C.uwsgi_cache_enabled()) == 0 { return false } k := C.CString(key) defer C.free(unsafe.Pointer(k)) kl := len(key) C.uwsgi_cache_rlock() if int(C.uwsgi_cache_exists(k, C.uint16_t(kl))) > 0 { C.uwsgi_cache_rwunlock() return true } C.uwsgi_cache_rwunlock() return false }
// remove an intem from the cache func CacheDel(key string) bool { if int(C.uwsgi_cache_enabled()) == 0 { return false } k := C.CString(key) defer C.free(unsafe.Pointer(k)) kl := len(key) C.uwsgi_cache_wlock() if int(C.uwsgi_cache_del(k, C.uint16_t(kl), C.uint64_t(0))) < 0 { C.uwsgi_cache_rwunlock() return false } C.uwsgi_cache_rwunlock() return true }
// check if an item exists in the cache func CacheExists(key string) bool { if (C.uwsgi.caches) == nil { return false } k := C.CString(key) defer C.free(unsafe.Pointer(k)) kl := len(key) C.uwsgi_cache_rlock(C.uwsgi.caches) if int(C.uwsgi_cache_exists2(C.uwsgi.caches, k, C.uint16_t(kl))) > 0 { C.uwsgi_cache_rwunlock(C.uwsgi.caches) return true } C.uwsgi_cache_rwunlock(C.uwsgi.caches) return false }
// remove an intem from the cache func CacheDel(key string) bool { if (C.uwsgi.caches) == nil { return false } k := C.CString(key) defer C.free(unsafe.Pointer(k)) kl := len(key) C.uwsgi_cache_wlock(C.uwsgi.caches) if int(C.uwsgi_cache_del2(C.uwsgi.caches, k, C.uint16_t(kl), C.uint64_t(0), C.uint16_t(0))) < 0 { C.uwsgi_cache_rwunlock(C.uwsgi.caches) return false } C.uwsgi_cache_rwunlock(C.uwsgi.caches) return true }
// put an item in the cache func CacheSetFlags(key string, p []byte, expires uint64, flags int) bool { if int(C.uwsgi_cache_enabled()) == 0 { return false } k := C.CString(key) defer C.free(unsafe.Pointer(k)) kl := len(key) v := unsafe.Pointer(&p[0]) vl := len(p) C.uwsgi_cache_wlock() if int(C.uwsgi_cache_set(k, C.uint16_t(kl), (*C.char)(v), C.uint64_t(vl), C.uint64_t(expires), C.uint16_t(flags))) < 0 { C.uwsgi_cache_rwunlock() return false } C.uwsgi_cache_rwunlock() return true }