diff --git a/include/titan/prioritized_cache.h b/include/titan/prioritized_cache.h new file mode 100644 index 000000000..10edff1fb --- /dev/null +++ b/include/titan/prioritized_cache.h @@ -0,0 +1,29 @@ +#pragma once +#include "rocksdb/cache.h" + +namespace rocksdb { +namespace titandb { + +class PrioritizedCache : public Cache { + public: + // Constructs a PrioritizedCache, which is a wrapper + // of rocksdb Cache + PrioritizedCache(std::shared_ptr cache, Cache::Priority priority); + ~PrioritizedCache(); + + // Get the Cache ptr + std::shared_ptr GetCache(); + + // always insert into the cache with the priority when init, + // regardless of user provided option + Status Insert(const Slice& key, void* value, size_t charge, + void (*deleter)(const Slice& key, void* value), + Cache::Handle** handle, Cache::Priority /*priority*/) override; + + private: + std::shared_ptr cache_; + Cache::Priority priority_; +}; + +} // namespace titandb +} // namespace rocksdb \ No newline at end of file diff --git a/src/prioritized_cache.cc b/src/prioritized_cache.cc new file mode 100644 index 000000000..385226ef3 --- /dev/null +++ b/src/prioritized_cache.cc @@ -0,0 +1,23 @@ +#include "titan/prioritized_cache.h" + +namespace rocksdb { +namespace titandb { + +PrioritizedCache::PrioritizedCache(std::shared_ptr cache, + Cache::Priority priority) + : cache_(cache), priority_(priority) {} + +PrioritizedCache::~PrioritizedCache() {} + +std::shared_ptr PrioritizedCache::GetCache() { return cache_; } + +Status PrioritizedCache::Insert(const Slice& key, void* value, size_t charge, + void (*deleter)(const Slice& key, void* value), + Cache::Handle** handle, + Cache::Priority /*priority*/) { + assert(cache_); + return cache_->Insert(key, value, charge, deleter, handle, priority_); +} + +} // namespace titandb +} // namespace rocksdb \ No newline at end of file