Files
004_comission/siutinchu/ENGG1330-Computer-Programming-I/readme.md
louiscklaw 7e9b533da2 update,
2025-01-31 21:05:22 +08:00

13 lines
884 B
Markdown

A LRU cache is a special kind of cache that defines the way of evicting item from the cache when it is full. Its policy is to evict the least recently used item.
For example,
- a cache having capacity of 4 and is currently storing
`[[1, '101'], [2, '102'], [3, '103'], [4, '104']]`,
- where the 1st (leftmost) item [1, '101'] is the least recently used and
- the last (rightmost) item [4, '104'] is the most recently used.
- When the item [2, '102'] is accessed,
- the cache becomes [[1, '101'], [3, '103'], [4, '104'], [2, '102']] as the item [2, '102'] becomes the most recently used.
- When another item [10, '110'] is pushed into the cache,
- the cache cannot hold all of the items and
- must evict the least recently used item which is [1, '101'] and
- the cache becomes [[3, '103'], [4, '104'], [2, '102'], [10, '110']].