Skip to content

Instantly share code, notes, and snippets.

View mrcrowl's full-sized avatar

mrcrowl

View GitHub Profile
@dherges
dherges / lru-cache.ts
Last active May 26, 2023 04:39
Simple LRU Cache in TypeScript
class LruCache<T> {
private values: Map<string, T> = new Map<string, T>();
private maxEntries: number = 20;
public get(key: string): T {
const hasKey = this.values.has(key);
let entry: T;
if (hasKey) {
// peek the entry, re-insert for LRU strategy