0Pricing
Flask Academy · Lesson

Memoize Expensive Functions

Cache function results by arguments.

Beyond Whole Views

Sometimes only one slow helper is the problem, not the whole page. Memoization caches a function result keyed by its arguments.

The memoize Decorator

You wrap a function with @cache.memoize(). Same arguments return the stored result instead of recomputing it. 💡

@cache.memoize()
def heavy(n):
    return slow_calc(n)

All lessons in this course

  1. Set Up Flask-Caching
  2. Cache a View with cached
  3. Memoize Expensive Functions
  4. Invalidate and Expire Cache Entries
← Back to Flask Academy