UNPKG

lrufy

Version:

A feature-rich LRU cache implementation with TTL support, custom sizing, and event hooks

53 lines (52 loc) 1.41 kB
/** * Represents a node in a doubly linked list */ export declare class Node<K, V> { key: K; value: V; prev: Node<K, V> | null; next: Node<K, V> | null; size: number; expiry: number | null; /** * Creates a new node * @param key - The key associated with this node * @param value - The value stored in this node */ constructor(key: K, value: V); } /** * A doubly linked list implementation to track LRU order */ export declare class DoublyLinkedList<K, V> { head: Node<K, V> | null; tail: Node<K, V> | null; length: number; /** * Adds a node to the front of the list (most recently used) * @param node - The node to add * @returns The added node */ addToFront(node: Node<K, V>): Node<K, V>; /** * Removes a node from the list * @param node - The node to remove * @returns The removed node */ remove(node: Node<K, V>): Node<K, V>; /** * Moves a node to the front of the list (marks as recently used) * @param node - The node to move to the front * @returns The moved node */ moveToFront(node: Node<K, V>): Node<K, V>; /** * Removes the least recently used node (from the tail) * @returns The removed node or null if the list is empty */ removeTail(): Node<K, V> | null; /** * Clears the linked list */ clear(): void; }