LRU Cache is a Least Recently Used (LRU) cache implementation designed to optimize data retrieval by storing frequently accessed items. Wikipedia
To install the LRU Cache, follow these steps:
-
Clone the repo:
git clone https://github.com/3d2069940/lru_cache.git && cd lru_cache
-
And just copy
lru_cache.hpp
fromlru_cache/src
right into your project! -
Optional step. If you want to build tests and benchmark install the following dependencies:
-
Optional step. Now run these commands in the
lru_cache
directory:cmake -B build -DCMAKE_BUILD_TYPE=Release .
cmake --build build -j
-
Optional step. It's compiled. Simply run:
./build/tests && ./build/benchmark_exec
#include <iostream>
#include "lru_cache.hpp"
int main()
{
LRUCache::Cache<int, std::string> cache;
cache.put(1, "string");
auto * cacheEntry = cache.get(1);
if (cacheEntry != nullptr)
std::cout << *cacheEntry << std::endl; // prints "string"
}
You can find example usage scenarios in the examples
directory. These examples demonstrate how to implement the LRU Cache in different contexts
This project is licensed under the MIT License. See the LICENSE file for details.