From 5085a83850856c72d1d309b2f641b65f7537eee6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Vavru=C5=A1a?= <marek.vavrusa@nic.cz>
Date: Fri, 20 Mar 2015 00:08:13 +0100
Subject: [PATCH] lib/cache: exported cache storage

---
 lib/cache.c | 23 +++--------------------
 lib/cache.h | 11 +++--------
 2 files changed, 6 insertions(+), 28 deletions(-)

diff --git a/lib/cache.c b/lib/cache.c
index f8ff59982..2a48f7b49 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -28,7 +28,9 @@
 #include "lib/cache.h"
 #include "lib/defines.h"
 
-#define db_api namedb_lmdb_api()
+/** Used cache storage engine (default LMDB) */
+const namedb_api_t *(*kr_cache_storage)(void) = namedb_lmdb_api;
+#define db_api kr_cache_storage()
 
 namedb_t *kr_cache_open(const char *handle, mm_ctx_t *mm, size_t maxsize)
 {
@@ -232,22 +234,3 @@ int kr_cache_clear(namedb_txn_t *txn)
 
 	return db_api->clear(txn);
 }
-
-int kr_cache_prune(namedb_txn_t *txn, uint32_t timestamp)
-{
-	/* Whole cache sweep is not feasible as we don't have a list of items sorted
-	 * by age nor any sort of LRU/MRU, completely random replace is not possible
-	 * as well.
-	 * - The LMDB also can't delete items when the MAPSIZE is reached.
-	 * - So we're probably need to iteratively scan the LMDB and prune aged
-	 *   items.
-	 * - This is not ideal, because queries won't be able to write to cache
-	 *   until at least some entry ages out.
-	 * - Idea - make poor man's LRU with two databases doing following:
-	 *   - Fill up 1, mark that it's unwritable
-	 *   - Fill up 2, mark that it's unwritable
-	 *   - Clear 1, all writes will now go in there
-	 *   - This gives us LR(written) with resolution 2
-	 */
-	return KNOT_EOK;
-}
diff --git a/lib/cache.h b/lib/cache.h
index 850d88676..23c864b94 100644
--- a/lib/cache.h
+++ b/lib/cache.h
@@ -32,6 +32,9 @@ struct kr_cache_rrset
 	uint8_t  data[];
 };
 
+/** Used storage API for cache (default LMDB) */
+extern const namedb_api_t *(*kr_cache_storage)(void);
+
 /**
  * Open/create persistent cache in given path.
  * @param handle Path to existing directory where the DB should be created.
@@ -115,12 +118,4 @@ int kr_cache_remove(namedb_txn_t *txn, const knot_rrset_t *rr);
  */
 int kr_cache_clear(namedb_txn_t *txn);
 
-/**
- * Clear aged items from the database.
- * @param txn transaction instance
- * @param timestamp current time
- * @return KNOT_E*
- */
-int kr_cache_prune(namedb_txn_t *txn, uint32_t timestamp);
-
 /** @} */
-- 
GitLab