diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-11-02 17:49:09 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-11-02 17:49:09 +0300 |
commit | f678526b2089826fba0299c88b9258bc48f748c4 (patch) | |
tree | b74c641d73e660bb9a6147335a646a468cb54d06 /src/kvstorage.c | |
parent | b50b716c78c39249e15b92132e2ee9d75639be17 (diff) | |
download | rspamd-f678526b2089826fba0299c88b9258bc48f748c4.tar.gz rspamd-f678526b2089826fba0299c88b9258bc48f748c4.zip |
* Implement sqlite3 backend for kvstorage.
Diffstat (limited to 'src/kvstorage.c')
-rw-r--r-- | src/kvstorage.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/kvstorage.c b/src/kvstorage.c index f1862f275..41b787dc5 100644 --- a/src/kvstorage.c +++ b/src/kvstorage.c @@ -157,6 +157,18 @@ rspamd_kv_storage_insert (struct rspamd_kv_storage *storage, gpointer key, } } + /* First try to search it in cache */ + elt = storage->cache->lookup_func (storage->cache, key); + if (elt) { + if (elt->flags & KV_ELT_DIRTY) { + /* Element is in backend storage queue */ + elt->flags |= KV_ELT_NEED_FREE; + } + else { + g_slice_free1 (ELT_SIZE (elt), elt); + } + } + /* Insert elt to the cache */ elt = storage->cache->insert_func (storage->cache, key, data, len); if (elt == NULL) { @@ -346,12 +358,12 @@ rspamd_kv_storage_set_array (struct rspamd_kv_storage *storage, gpointer key, return FALSE; } /* Get element size */ - es = (guint *)elt->data; + es = (guint *)ELT_DATA (elt); if (elt_num > (elt->size - sizeof (guint)) / (*es)) { /* Invalid index */ return FALSE; } - target = (gchar *)elt->data + sizeof (guint) + (*es) * elt_num; + target = (gchar *)ELT_DATA (elt) + sizeof (guint) + (*es) * elt_num; if (len != *es) { /* Invalid size */ return FALSE; @@ -383,12 +395,12 @@ rspamd_kv_storage_get_array (struct rspamd_kv_storage *storage, gpointer key, return FALSE; } /* Get element size */ - es = (guint *)elt->data; + es = (guint *)ELT_DATA (elt); if (elt_num > (elt->size - sizeof (guint)) / (*es)) { /* Invalid index */ return FALSE; } - target = elt->data + sizeof (guint) + (*es) * elt_num; + target = ELT_DATA (elt) + sizeof (guint) + (*es) * elt_num; *len = *es; *data = target; |