# Caching (and Memoization)

DevFeed: [Caching (and Memoization)](<https://devfeed.tech/articles/caching-and-memoization-40267.md>)

Original publisher: [Read original article](<https://www.jeremykun.com/2012/03/22/caching-and-memoization/>)

Published: 2012-03-22T11:09:57Z

Content type: tutorial

Language: en

Sources: [Jeremy Kun](<https://devfeed.tech/sources/jeremy-kun.md>)

Topics: [Caching](<https://devfeed.tech/topics/caching.md>), [Python](<https://devfeed.tech/topics/python.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [caching](<https://devfeed.tech/tags/caching.md>), [computer-science](<https://devfeed.tech/tags/computer-science.md>), [function](<https://devfeed.tech/tags/function.md>), [python](<https://devfeed.tech/tags/python.md>)

## AI overview

This tutorial explains caching and memoization as techniques for remembering function results to avoid repeated computation. It presents a Python decorator that caches function results and discusses limitations involving unhashable arguments and unbounded cache growth.

## Source excerpt

Problem: Remember results of a function call which requires a lot of computation. Solution: (in Python) def memoize(f): cache = {} def memoizedFunction(*args): if args not in cache: cache[args] = f(*args) return cache[args] memoizedFunction.cache = cache return memoizedFunction @memoize def f(): ... Discussion: You might not use monoids or eigenvectors on a daily basis, but you use caching far more often than you may know. Caching the results of some operation is so prevalent in computer science that the world would slow down considerably without it.