-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore]: demo usage of memecache with fifo, lifo using multithreading
- Loading branch information
Showing
2 changed files
with
74 additions
and
15 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 |
---|---|---|
@@ -1,28 +1,44 @@ | ||
#include "include/cache.hpp" | ||
#include "include/fifo_cache_policy.hpp" | ||
#include "include/lifo_cache_policy.hpp" | ||
#include <iostream> | ||
|
||
// alias for easy class typing | ||
template <typename Key, typename Value> | ||
using fifo_cache_t = typename caches::fixed_sized_cache<Key, Value, caches::FIFOCachePolicy>; | ||
template <typename Key, typename Value> | ||
using lifo_cache_t = typename caches::fixed_sized_cache<Key, Value, caches::LIFOCachePolicy>; | ||
|
||
int main() | ||
{ | ||
|
||
std::cout << "Hello Enterpret!\n"; | ||
|
||
constexpr std::size_t CACHE_SIZE = 256; | ||
fifo_cache_t<std::string, int> cache(CACHE_SIZE); | ||
fifo_cache_t<std::string, int> fifo_cache(CACHE_SIZE); | ||
lifo_cache_t<std::string, int> lifo_cache(CACHE_SIZE); | ||
|
||
cache.Put("Hello", 100); | ||
cache.Put("world", 6996); | ||
fifo_cache.Put("Hello", 80); | ||
fifo_cache.Put("enterpret", 81); | ||
|
||
std::cout << "Value for key '" | ||
lifo_cache.Put("Backend", 40); | ||
lifo_cache.Put("intern", 4); | ||
|
||
std::cout << "Using FIFO Eviction Policy\n" | ||
<< "Value for key '" | ||
<< "Hello" | ||
<< "': " << cache.Get("Hello") << '\n'; | ||
<< "': " << fifo_cache.Get("Hello") << '\n'; | ||
std::cout << "Value for key '" | ||
<< "enterpret" | ||
<< "': " << fifo_cache.Get("enterpret") << '\n'; | ||
|
||
std::cout << "Using LIFO Eviction Policy\n" | ||
<< "Value for key '" | ||
<< "Backend" | ||
<< "': " << lifo_cache.Get("Backend") << '\n'; | ||
std::cout << "Value for key '" | ||
<< "world" | ||
<< "': " << cache.Get("world") << '\n'; | ||
<< "intern" | ||
<< "': " << lifo_cache.Get("intern") << '\n'; | ||
|
||
return 0; | ||
} |
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