Skip to content

3d2069940/lru_cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LRU Cache

Description

LRU Cache is a Least Recently Used (LRU) cache implementation designed to optimize data retrieval by storing frequently accessed items. Wikipedia

Table of Contents

Installation

To install the LRU Cache, follow these steps:

  1. Clone the repo:

    git clone https://github.com/3d2069940/lru_cache.git && cd lru_cache
  2. And just copy lru_cache.hpp from lru_cache/src right into your project!

  3. Optional step. If you want to build tests and benchmark install the following dependencies:

  4. Optional step. Now run these commands in the lru_cache directory:

    cmake -B build -DCMAKE_BUILD_TYPE=Release .
    cmake --build build -j
  5. Optional step. It's compiled. Simply run:

    ./build/tests && ./build/benchmark_exec

Usage

#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"
}

Examples

You can find example usage scenarios in the examples directory. These examples demonstrate how to implement the LRU Cache in different contexts

License

This project is licensed under the MIT License. See the LICENSE file for details.

Releases

No releases published

Packages

No packages published