-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: haoxiang47 <[email protected]>
- Loading branch information
1 parent
4dc4ba8
commit 25fc0ff
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "prioritized_cache.h" | ||
|
||
namespace rocksdb { | ||
namespace titandb { | ||
|
||
PrioritizedCache::PrioritizedCache(std::shared_ptr<Cache> cache) : | ||
cache_(cache) {} | ||
|
||
std::shared_ptr<Cache> PrioritizedCache::GetPrioritizedCache() { | ||
return cache_; | ||
} | ||
|
||
Status PrioritizedCache::HighPriCacheInsert(const Slice& key, void* value, size_t charge, | ||
void (*deleter)(const Slice& key, void* value), | ||
Cache::Handle** handle) { | ||
return cache_->Insert(key, value, charge, deleter, handle, Cache::Priority::HIGH); | ||
} | ||
|
||
Status PrioritizedCache::LowPriCacheInsert(const Slice& key, void* value, size_t charge, | ||
void (*deleter)(const Slice& key, void* value), | ||
Cache::Handle** handle) { | ||
return cache_->Insert(key, value, charge, deleter, handle, Cache::Priority::LOW); | ||
} | ||
|
||
} // namespace titandb | ||
} // namespace rocksdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
#include "rocksdb/cache.h" | ||
#include "rocksdb/env.h" | ||
|
||
namespace rocksdb { | ||
namespace titandb { | ||
|
||
class PrioritizedCache { | ||
public: | ||
|
||
// Constructs a PrioritizedCache, which is a wrapper | ||
// of rocksdb Cache | ||
PrioritizedCache(std::shared_ptr<Cache> cache); | ||
~PrioritizedCache(); | ||
|
||
// Get the Cache ptr | ||
std::shared_ptr<Cache> GetPrioritizedCache(); | ||
|
||
// always insert into the cache with high-priority, | ||
// regardless of user provided option | ||
Status HighPriCacheInsert(const Slice& key, void* value, size_t charge, | ||
void (*deleter)(const Slice& key, void* value), | ||
Cache::Handle** handle = nullptr); | ||
|
||
// always insert into the cache with low-priority, | ||
// regardless of user provided option | ||
Status LowPriCacheInsert(const Slice& key, void* value, size_t charge, | ||
void (*deleter)(const Slice& key, void* value), | ||
Cache::Handle** handle = nullptr); | ||
|
||
private: | ||
std::shared_ptr<Cache> cache_; | ||
}; | ||
|
||
|
||
} // namespace titandb | ||
} // namespace rocksdb |