GithubHelp home page GithubHelp logo

lrucache's Introduction

LRUCache

Overview

It is an implementation of a cache that implements a Least Recently Used (LRU) eviction policy. The policy is only enforced when the cache is updated via the AddOrUpdate method; i.e. there are no background threads periodically sweeping out data that hasn't been recently accessed.

The solution LRUCache.sln contains two projects:

  • DataStructures.csproj: this contains the ICache interface as specified by the coding challenge, and a Cache class that implements this interface using the LRU policy. Both classes are in the FoneDynamics.DataStructures namespace.
  • DataStructures.Tests.csproj: the unit test suite for this project. Code coverage is measured at 100% using JetBrains dotCover. The tests are implemented using NUnit 3.

100% Code Coverage in Unit Tests

Both projects use .NET Framework 4.7.1 as their target framework.

All operations on this cache have O(1) time complexity; i.e. the time taken to perform an operation is not influenced by the number of items in the cache.

ICache<TKey, TValue> Interface

The following interface is implemented:

public interface ICache<TKey, TValue>
{
    /// <summary>
    /// Adds the value to the cache against the specified key.
    /// If the key already exists, its value is updated.
    /// </summary>
    void AddOrUpdate(TKey key, TValue value);

    /// <summary>
    /// Attempts to get the value from the cache against the specified key
    /// and returns true if the key exists in the cache.
    /// </summary>
    bool TryGetValue(TKey key, out TValue value);
}

Both calls on this interface make key the most recently used of all the keys stored by the cache.

lrucache's People

Contributors

jimmcslim avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.