Skip to content
    Architecton

    CACHING · 8 MIN

    Caching

    A cache stores frequently read data in fast memory to avoid repeating slow work.

    ARCH explains

    • Cache hit: data found in cache. Miss: fetch from the database and store it.
    • Eviction policies like LRU remove the least recently used entry when full.
    • Invalidation (keeping cache fresh) is the hard part — use TTLs or write-through.

    Real world: Keeping your most-used books on your desk instead of the library.

    Watch it move

    A

    get(A) → MISS

    1/6

    Code

    from functools import lru_cache
    @lru_cache(maxsize=128)
    def fib(n):
        return n if n < 2 else fib(n-1) + fib(n-2)
    print(fib(40))
    Output ›
    102334155
    Try it in the online compiler →

    Checkpoint quiz

    LRU evicts the entry that was…