service/lrucache.js
// Writing node becomes new Head of LinkedList
Writing node becomes new Head of LinkedList
Writing node becomes new Head of LinkedList
write(key, value){
      this.ensureLimit();
      if(!this.head){
        this.head = this.tail = new Node(key, value);
      }else{
        const node = new Node(key, value, this.head);
        this.head.prev = node;
        this.head = node;
      }
      this.map[key] = this.head;
      this.size++;
    }
write ( key , value ) { this . ensureLimit ( ) ; if ( ! this . head ) { this . head = this . tail = new Node ( key , value ) ; } else { const node = new Node ( key , value , this . head ) ; this . head . prev = node ; this . head = node ; } this . map [ key ] = this . head ; this . size ++ ; }
Writing node becomes new Head of LinkedList
Writing node becomes new Head of LinkedList
/* Check limit, if exceeded, remove tail node  
      ** removed tail node's previous node becomes the new tail node
      **/ /* If head doesn't exist, this is the first item in cache
        ** it becomes the head and tail Node
        **/ /* Writing node's next node set as current head node, previous node as null 
        ** this will become the new head node
        **/ /* Current head node's previous node set to writing node */ /* New head node set to writing node 
        ** previous head node is new head node's next node
        ** therefore previous head node's previous node is the new head node
        **/ /* Update the cache map */