structure for future response caching

This commit is contained in:
roberto@goyle
2011-02-18 19:31:58 +01:00
parent 4badecdbbc
commit 86fcd13dd9
3 changed files with 58 additions and 2 deletions
+3 -1
View File
@@ -57,6 +57,7 @@ char *uwsgi_cache_get(char *key, uint16_t keylen, uint64_t *valsize) {
uint64_t index = uwsgi_cache_get_index(key, keylen);
if (index) {
if (uwsgi.cache_items[index].flags & UWSGI_CACHE_FLAG_UNGETTABLE) return NULL;
*valsize = uwsgi.cache_items[index].valsize;
uwsgi.cache_items[index].hits++;
return uwsgi.cache+(index*uwsgi.cache_blocksize);
@@ -104,7 +105,7 @@ int uwsgi_cache_del(char *key, uint16_t keylen) {
return ret;
}
int uwsgi_cache_set(char *key, uint16_t keylen, char *val, uint64_t vallen, uint64_t expires) {
int uwsgi_cache_set(char *key, uint16_t keylen, char *val, uint64_t vallen, uint64_t expires, uint16_t flags) {
uint64_t index = 0, last_index = 0 ;
@@ -141,6 +142,7 @@ int uwsgi_cache_set(char *key, uint16_t keylen, char *val, uint64_t vallen, uint
uci->expires = expires;
uci->djbhash = djb33x_hash(key, keylen);
uci->hits = 0;
uci->flags = flags;
memcpy(uci->key, key, keylen);
memcpy(uwsgi.cache+(index*uwsgi.cache_blocksize), val, vallen);
+4 -1
View File
@@ -193,6 +193,9 @@ extern int pivot_root(const char * new_root, const char * put_old);
#endif
#define UWSGI_CACHE_MAX_KEY_SIZE 2048
#define UWSGI_CACHE_FLAG_UNGETTABLE 0x0001
#define uwsgi_cache_update_start(x, y, z) uwsgi_cache_set(x, y, "", 0, CACHE_FLAG_UNGETTABLE)
union uwsgi_sockaddr {
struct sockaddr sa;
@@ -242,7 +245,7 @@ struct uwsgi_queue_item {
// maintain alignment here !!!
struct uwsgi_cache_item {
// unused
uint16_t unused;
uint16_t flags;
// size of the key
uint16_t keysize;
// djb hash of the key
+51
View File
@@ -0,0 +1,51 @@
// uWSGI writer
void simple_writer_init(struct wsgi_request *wsgi_req) {}
void simple_writer_end(struct wsgi_request *wsgi_req) {}
ssize_t simple_writer(struct wsgi_request *wsgi_req, char *buf, size_t len) {
return write(wsgi_req->poll.fd, buf, len);
}
void cache_writer_init(struct wsgi_request *wsgi_req) {
if (wsgi_req->cache_it) {
// lock cache write
if (uwsgi_cache_update_start(wsgi_req->uri, wsgi_req->uri_len)) {
uwsgi_log("unable to write data to uwsgi cache\n");
wsgi_req->cache_it = 0;
}
}
}
ssize_t cache_writer(struct wsgi_request *wsgi_req, char *buf, size_t len) {
if (wsgi_req->cache_it) {
// lock cache write
if (uwsgi_cache_update(wsgi_req->uri, wsgi_req->uri_len, buf, len, wsgi_req->cache_expires)) {
uwsgi_log("unable to write data to uwsgi cache\n");
uwsgi_cache_del(sgi_req->uri, wsgi_req->uri_len);
}
// unlock cache
}
return write(wsgi_req->poll.fd, buf, len);
}
void cache_writer_end(struct wsgi_request *wsgi_req) {
if (wsgi_req->cache_it) {
// finish cache update (lock write it)
uwsgi_cache_update_finalize(wsgi_req->uri, wsgi_req->uri_len);
}
}
void memcached_writer_init(struct wsgi_request *wsgi_req) {
//open connection to memcached and create entry
}
void memcached_writer_end(struct wsgi_request *wsgi_req) {
// close connection with memcached
}
ssize_t memcached_writer(struct wsgi_request *wsgi_req, char *buf, size_t len) {
}