示例#1
0
文件: uwsgi.go 项目: nwalker/uwsgi
// 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
}
示例#2
0
文件: uwsgi.go 项目: nwalker/uwsgi
// 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
}
示例#3
0
文件: uwsgi.go 项目: nwalker/uwsgi
// 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
}
示例#4
0
文件: uwsgi.go 项目: kihon10/uwsgi
// 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
}
示例#5
0
文件: uwsgi.go 项目: kihon10/uwsgi
// 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
}
示例#6
0
文件: uwsgi.go 项目: nwalker/uwsgi
// 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
}