diff --git a/lib/cache.c b/lib/cache.c index f8ff599826c27a1c50019c5cdca1ae36753c5c3e..2a48f7b49c1c5f8973a4a89318f7b6451b8861e8 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 850d88676a867340e076ce37c2e94df0485c7f9d..23c864b94fc2d0a1e9b5f421bc845b8450f38aa9 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); - /** @} */