Giter VIP home page Giter VIP logo

java12-fundamentals-cache-implementations-workshop's Introduction

Build Status License: GPL v3

java12-fundamentals-cache-implementations-workshop

preface

  • goals of this workshop

    • understand concept of LRU cache
    • understand concept of LFU cache
    • implement LRU and LFU cache
    • see how guards are useful in list implementations
  • workshop: lfu.workshop, lru.workshop

    • during implementation use classes from list
  • answers: lfu.answers, lru.answers

least recently used (LRU)

  • discards the least recently used items first
  • operations
    • get(key) - get the value if the key exists in the cache, otherwise null
    • put(key, value) - set or insert the value if the key is not already present
      • when the cache reached its capacity, it should invalidate the least recently used item before inserting a new item
    • both in O(1)
  • solutions
    • LinkedHashMap<Integer, Integer> + overridden removeEldestEntry method
      • remark: LinkedHashMap has two iteration order: access-order or insertion-order
    • map + double linked list

least frequently used

  • is nothing but removing least frequently used item from the cache to put the new data into the cache
  • is sometimes combined with a Least Recently Used algorithm and called LRFU
  • operations
    • get(key) - get the value if the key exists in the cache, otherwise null
    • put(key, value) - set or insert the value if the key is not already present
      • when the cache reached its capacity, it should invalidate the least recently used item before inserting a new item
    • both in O(1)
  • may seem like an intuitive approach to memory management it is not without faults
    • consider an item in memory which is referenced repeatedly for a short period of time and is not accessed again for an extended period of time
    • an explicit LFU system is fairly uncommon; instead, there are hybrids that utilize LFU concepts
  • solution
    • cache map, frequency map, frequency list

java12-fundamentals-cache-implementations-workshop's People

Watchers

 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.