← All Exercises

Decorator with LRU Cache

intermediatepython~15min

Background

Memoization with LRU cache dramatically speeds up repeated function calls with same arguments.

Problem

Create a decorator that adds LRU caching to expensive function calls with configurable cache size.

Input

An expensive function

Output

A cached version of the function

Sample tests

Sample 1

Input: cached_fib(100)
Expected: fast result

Your solution

Learning objective

Learn memoization and decorator composition