René's URL Explorer Experiment


Title: Caching in Python Using the LRU Cache Strategy – Real Python

Open Graph Title: Caching in Python Using the LRU Cache Strategy – Real Python

Description: Caching is an essential optimization technique. In this tutorial, you'll learn how to use Python's @lru_cache decorator to cache the results of your functions using the LRU cache strategy. This is a powerful technique you can use to leverage the power of caching in your implementations.

Open Graph Description: Caching is an essential optimization technique. In this tutorial, you'll learn how to use Python's @lru_cache decorator to cache the results of your functions using the LRU cache strategy. This is a powerful technique you can use to leverage the power of caching in your implementations.

Mail addresses
?subject=Python article for you&body=Caching in Python Using the LRU Cache Strategy on Real Python https://realpython.com/lru-cache-python/

Opengraph URL: https://realpython.com/lru-cache-python/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
{
  "@context": "http://schema.org",
  "@type": "Article",
  "headline": "Caching in Python Using the LRU Cache Strategy",
  "image": {
    "@type": "ImageObject",
    "url": "https://files.realpython.com/media/LRU_cache-in-Python_Watermarked.0a0ccb7f43c1.jpg",
    "width": 1920,
    "height": 1080
  },
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://realpython.com/lru-cache-python/",
    "lastReviewed": "2023-06-23",
    "author": {
      "@type": "Person",
      "name": "Santiago Valdarrama",
      "image": "https://realpython.com/cdn-cgi/image/width=716,height=716,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/2.676ecffdae49.jpg",
      "url": "https://realpython.com/team/svaldarrama/",
      "affiliation": {
        "@type": "Organization",
        "@id": "https://realpython.com/#organization",
        "name": "Real Python",
        "url": "https://realpython.com",
        "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
      }
    },
    "reviewedBy": [
      {
        "@type": "Person",
        "name": "Aldren Santos",
        "image": "https://realpython.com/cdn-cgi/image/width=500,height=500,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Aldren_Santos_Real_Python.6b0861d8b841.png",
        "url": "https://realpython.com/team/asantos/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Bartosz Zaczy\u0144ski",
        "image": "https://realpython.com/cdn-cgi/image/width=1694,height=1694,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/coders_lab_2109368.259b1599fbee.jpg",
        "url": "https://realpython.com/team/bzaczynski/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Geir Arne Hjelle",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/gahjelle.470149ee709e.jpg",
        "url": "https://realpython.com/team/gahjelle/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Joanna Jablonski",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/jjablonksi-avatar.e37c4f83308e.jpg",
        "url": "https://realpython.com/team/jjablonski/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Jacob Schmitt",
        "image": "https://realpython.com/cdn-cgi/image/width=400,height=400,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/profile-small_js.2f4d0d8da1ca.jpg",
        "url": "https://realpython.com/team/jschmitt/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      }
    ]
  },
  "datePublished": "2020-11-04T14:00:00+00:00",
  "dateModified": "2023-06-23T20:35:18.895688+00:00",
  "publisher": {
    "@type": "Organization",
    "@id": "https://realpython.com/#organization",
    "name": "Real Python",
    "url": "https://realpython.com",
    "logo": {
      "@type": "ImageObject",
      "url": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png",
      "width": 512,
      "height": 512
    },
    "description": "Real Python is a leading provider of online Python education and one of the largest language-specific online communities for software developers. It publishes high-quality learning resources, such as tutorials, books, and courses to an audience of millions of developers, data scientists, and machine learning engineers each month.",
    "slogan": "Become a Python Expert",
    "email": "info@realpython.com",
    "sameAs": [
      "https://github.com/realpython",
      "https://www.youtube.com/realpython",
      "https://twitter.com/realpython",
      "https://x.com/realpython",
      "https://www.linkedin.com/company/realpython-com/",
      "https://www.facebook.com/learnrealpython",
      "https://www.instagram.com/realpython",
      "https://www.tiktok.com/@realpython.com"
    ]
  },
  "author": {
    "@type": "Person",
    "name": "Santiago Valdarrama",
    "image": "https://realpython.com/cdn-cgi/image/width=716,height=716,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/2.676ecffdae49.jpg",
    "url": "https://realpython.com/team/svaldarrama/",
    "affiliation": {
      "@type": "Organization",
      "@id": "https://realpython.com/#organization",
      "name": "Real Python",
      "url": "https://realpython.com",
      "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
    }
  },
  "description": "Caching is an essential optimization technique. In this tutorial, you'll learn how to use Python's @lru_cache decorator to cache the results of your functions using the LRU cache strategy. This is a powerful technique you can use to leverage the power of caching in your implementations."
}

authorReal Python
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/LRU_cache-in-Python_Watermarked.0a0ccb7f43c1.jpg
og:imagehttps://files.realpython.com/media/LRU_cache-in-Python_Watermarked.0a0ccb7f43c1.jpg
twitter:creator@realpython
og:typearticle

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/lru-cache-python/
Python Tutorials →In-depth articles and video courseshttps://realpython.com/search?kind=article&kind=course&order=newest
Learning Paths →Guided study plans for accelerated learninghttps://realpython.com/learning-paths/
Quizzes & Exercises →Check your learning progresshttps://realpython.com/quizzes/
Browse Topics →Focus on a specific area or skill levelhttps://realpython.com/tutorials/all/
Community Chat →Learn with other Pythonistashttps://realpython.com/community/
Office Hours →Live Q&A calls with Python expertshttps://realpython.com/office-hours/
Podcast →Hear what’s new in the world of Pythonhttps://realpython.com/podcasts/rpp/
Books →Round out your knowledge and learn offlinehttps://realpython.com/products/books/
Reference →Concise definitions for common Python termshttps://realpython.com/ref/
Code Mentor →BetaPersonalized code assistance & learning toolshttps://realpython.com/mentor/
Unlock All Content →https://realpython.com/account/join/
More https://realpython.com/lru-cache-python/
Learner Storieshttps://realpython.com/learner-stories/
Python Newsletterhttps://realpython.com/newsletter/
Python Job Boardhttps://www.pythonjobshq.com
Meet the Teamhttps://realpython.com/team/
Become a Tutorial Writerhttps://realpython.com/write-for-us/
Become a Video Instructorhttps://realpython.com/become-an-instructor/
Searchhttps://realpython.com/search
https://realpython.com/search
Joinhttps://realpython.com/account/join/
Sign‑Inhttps://realpython.com/account/login/?next=%2Flru-cache-python%2F
Browse Topicshttps://realpython.com/tutorials/all/
Guided Learning Pathshttps://realpython.com/learning-paths/
Basicshttps://realpython.com/search?level=basics
Intermediatehttps://realpython.com/search?level=intermediate
Advancedhttps://realpython.com/search?level=advanced
aihttps://realpython.com/tutorials/ai/
algorithmshttps://realpython.com/tutorials/algorithms/
apihttps://realpython.com/tutorials/api/
best-practiceshttps://realpython.com/tutorials/best-practices/
careerhttps://realpython.com/tutorials/career/
communityhttps://realpython.com/tutorials/community/
databaseshttps://realpython.com/tutorials/databases/
data-sciencehttps://realpython.com/tutorials/data-science/
data-structureshttps://realpython.com/tutorials/data-structures/
data-vizhttps://realpython.com/tutorials/data-viz/
devopshttps://realpython.com/tutorials/devops/
djangohttps://realpython.com/tutorials/django/
dockerhttps://realpython.com/tutorials/docker/
editorshttps://realpython.com/tutorials/editors/
flaskhttps://realpython.com/tutorials/flask/
front-endhttps://realpython.com/tutorials/front-end/
gamedevhttps://realpython.com/tutorials/gamedev/
guihttps://realpython.com/tutorials/gui/
machine-learninghttps://realpython.com/tutorials/machine-learning/
newshttps://realpython.com/tutorials/news/
numpyhttps://realpython.com/tutorials/numpy/
projectshttps://realpython.com/tutorials/projects/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
testinghttps://realpython.com/tutorials/testing/
toolshttps://realpython.com/tutorials/tools/
web-devhttps://realpython.com/tutorials/web-dev/
web-scrapinghttps://realpython.com/tutorials/web-scraping/
Table of Contentshttps://realpython.com/lru-cache-python/#toc
Caching and Its Useshttps://realpython.com/lru-cache-python/#caching-and-its-uses
Implementing a Cache Using a Python Dictionaryhttps://realpython.com/lru-cache-python/#implementing-a-cache-using-a-python-dictionary
Caching Strategieshttps://realpython.com/lru-cache-python/#caching-strategies
Diving Into the Least Recently Used (LRU) Cache Strategyhttps://realpython.com/lru-cache-python/#diving-into-the-least-recently-used-lru-cache-strategy
Peeking Behind the Scenes of the LRU Cachehttps://realpython.com/lru-cache-python/#peeking-behind-the-scenes-of-the-lru-cache
Using @lru_cache to Implement an LRU Cache in Pythonhttps://realpython.com/lru-cache-python/#using-lru_cache-to-implement-an-lru-cache-in-python
Playing With Stairshttps://realpython.com/lru-cache-python/#playing-with-stairs
Timing Your Codehttps://realpython.com/lru-cache-python/#timing-your-code
Using Memoization to Improve the Solutionhttps://realpython.com/lru-cache-python/#using-memoization-to-improve-the-solution
Unpacking the Functionality of @lru_cachehttps://realpython.com/lru-cache-python/#unpacking-the-functionality-of-lru_cache
Adding Cache Expirationhttps://realpython.com/lru-cache-python/#adding-cache-expiration
Evicting Cache Entries Based on Both Time and Spacehttps://realpython.com/lru-cache-python/#evicting-cache-entries-based-on-both-time-and-space
Caching Articles With the New Decoratorhttps://realpython.com/lru-cache-python/#caching-articles-with-the-new-decorator
Conclusionhttps://realpython.com/lru-cache-python/#conclusion
https://realpython.com/feedback/survey/article/lru-cache-python/liked/?from=article-sidebar
https://realpython.com/feedback/survey/article/lru-cache-python/disliked/?from=article-sidebar
Caching in Python With lru_cache 39m · 7 lessons https://realpython.com/courses/caching-python-lru/
Santiago Valdarramahttps://realpython.com/lru-cache-python/#author
https://realpython.com/lru-cache-python/#reader-comments
intermediatehttps://realpython.com/tutorials/intermediate/
pythonhttps://realpython.com/tutorials/python/
Caching and Its Useshttps://realpython.com/lru-cache-python/#caching-and-its-uses
Implementing a Cache Using a Python Dictionaryhttps://realpython.com/lru-cache-python/#implementing-a-cache-using-a-python-dictionary
Caching Strategieshttps://realpython.com/lru-cache-python/#caching-strategies
Diving Into the Least Recently Used (LRU) Cache Strategyhttps://realpython.com/lru-cache-python/#diving-into-the-least-recently-used-lru-cache-strategy
Peeking Behind the Scenes of the LRU Cachehttps://realpython.com/lru-cache-python/#peeking-behind-the-scenes-of-the-lru-cache
Using @lru_cache to Implement an LRU Cache in Pythonhttps://realpython.com/lru-cache-python/#using-lru_cache-to-implement-an-lru-cache-in-python
Playing With Stairshttps://realpython.com/lru-cache-python/#playing-with-stairs
Timing Your Codehttps://realpython.com/lru-cache-python/#timing-your-code
Using Memoization to Improve the Solutionhttps://realpython.com/lru-cache-python/#using-memoization-to-improve-the-solution
Unpacking the Functionality of @lru_cachehttps://realpython.com/lru-cache-python/#unpacking-the-functionality-of-lru_cache
Adding Cache Expirationhttps://realpython.com/lru-cache-python/#adding-cache-expiration
Evicting Cache Entries Based on Both Time and Spacehttps://realpython.com/lru-cache-python/#evicting-cache-entries-based-on-both-time-and-space
Caching Articles With the New Decoratorhttps://realpython.com/lru-cache-python/#caching-articles-with-the-new-decorator
Conclusionhttps://realpython.com/lru-cache-python/#conclusion
Remove adshttps://realpython.com/account/join/
Caching in Python With lru_cachehttps://realpython.com/courses/caching-python-lru/
functools modulehttps://docs.python.org/3/library/functools.html
@lru_cache decoratorhttps://docs.python.org/3/library/functools.html#functools.lru_cache
5 Thoughts On Python Masteryhttps://realpython.com/bonus/python-mastery-course/
https://realpython.com/lru-cache-python/#caching-and-its-uses
Remove adshttps://realpython.com/account/join/
https://realpython.com/lru-cache-python/#implementing-a-cache-using-a-python-dictionary
dictionaryhttps://realpython.com/python-dicts/
installhttps://realpython.com/what-is-pip/#installing-packages-with-pip
requests libraryhttps://realpython.com/python-requests/
printedhttps://realpython.com/python-print/
https://realpython.com/lru-cache-python/#caching-strategies
https://realpython.com/lru-cache-python/#diving-into-the-least-recently-used-lru-cache-strategy
https://files.realpython.com/media/lru_cache_1_1.2eb80a8b24a3.png
https://files.realpython.com/media/lru_cache_2_1.8c4f225e79d0.png
Remove adshttps://realpython.com/account/join/
https://realpython.com/lru-cache-python/#peeking-behind-the-scenes-of-the-lru-cache
doubly linked listhttps://realpython.com/linked-lists-python/#how-to-use-doubly-linked-lists
hash maphttps://realpython.com/python-data-structures/#dictionaries-maps-and-hash-tables
https://files.realpython.com/media/cache_internal_representation_1.6fdd3a39fa28.png
Big O notationhttps://realpython.com/sorting-algorithms-python/#measuring-efficiency-with-big-o-notation
Big O Notation and Algorithm Analysis with Python Exampleshttps://stackabuse.com/big-o-notation-and-algorithm-analysis-with-python-examples/
https://realpython.com/lru-cache-python/#using-lru_cache-to-implement-an-lru-cache-in-python
https://realpython.com/lru-cache-python/#playing-with-stairs
https://files.realpython.com/media/7_ways_to_make_it_to_4th_stair.2dea6527a4b7.png
https://files.realpython.com/media/combination-jumps-to-7th-stair-lru-cache_1.385e09435b81.png
Recursion in Python: An Introductionhttps://realpython.com/python-recursion/
Remove adshttps://realpython.com/account/join/
https://realpython.com/lru-cache-python/#timing-your-code
timeit modulehttps://docs.python.org/3/library/timeit.html
importhttps://realpython.com/python-import/
official Python documentationhttps://docs.python.org/3/library/timeit.html
https://realpython.com/lru-cache-python/#using-memoization-to-improve-the-solution
https://files.realpython.com/media/tree.3ebda400089a.png
Memoization in Pythonhttps://towardsdatascience.com/memoization-in-python-57c0a738179a
Python 3.8https://realpython.com/python38-new-features/
Remove adshttps://realpython.com/account/join/
https://realpython.com/lru-cache-python/#unpacking-the-functionality-of-lru_cache
https://realpython.com/lru-cache-python/#adding-cache-expiration
Atom feedhttps://en.wikipedia.org/wiki/Atom_(Web_standard)
terminalhttps://realpython.com/terminal-commands/
HTTPShttps://realpython.com/python-https/
sleepshttps://realpython.com/python-sleep/
issue 84https://github.com/kurtmckee/feedparser/issues/84
PEP 476https://www.python.org/dev/peps/pep-0476/
Remove adshttps://realpython.com/account/join/
https://realpython.com/lru-cache-python/#evicting-cache-entries-based-on-both-time-and-space
Primer on Python Decoratorshttps://realpython.com/primer-on-python-decorators/
Python Decorators 101https://realpython.com/courses/python-decorators-101/
https://realpython.com/lru-cache-python/#caching-articles-with-the-new-decorator
https://realpython.com/lru-cache-python/#conclusion
cachetoolshttps://github.com/tkem/cachetools/
https://realpython.com/feedback/survey/article/lru-cache-python/liked/?from=article-footer
https://realpython.com/feedback/survey/article/lru-cache-python/disliked/?from=article-footer
Caching in Python With lru_cachehttps://realpython.com/courses/caching-python-lru/
https://realpython.com/team/svaldarrama/
» More about Santiagohttps://realpython.com/team/svaldarrama/
https://realpython.com/team/asantos/
Aldrenhttps://realpython.com/team/asantos/
https://realpython.com/team/bzaczynski/
Bartoszhttps://realpython.com/team/bzaczynski/
https://realpython.com/team/gahjelle/
Geir Arnehttps://realpython.com/team/gahjelle/
https://realpython.com/team/jjablonski/
Joannahttps://realpython.com/team/jjablonski/
https://realpython.com/team/jschmitt/
Jacobhttps://realpython.com/team/jschmitt/
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=lru-cache-python
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=lru-cache-python
https://realpython.com/feedback/survey/article/lru-cache-python/liked/?from=article-comments
https://realpython.com/feedback/survey/article/lru-cache-python/disliked/?from=article-comments
LinkedInhttps://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Frealpython.com%2Flru-cache-python%2F
Twitterhttps://twitter.com/intent/tweet/?text=Interesting%20Python%20article%20on%20%40realpython%3A%20Caching%20in%20Python%20Using%20the%20LRU%20Cache%20Strategy&url=https%3A%2F%2Frealpython.com%2Flru-cache-python%2F
Blueskyhttps://bsky.app/intent/compose?text=Interesting%20Python%20article%20on%20%40realpython.com%3A%20Caching%20in%20Python%20Using%20the%20LRU%20Cache%20Strategy%20https%3A%2F%2Frealpython.com%2Flru-cache-python%2F
Facebookhttps://facebook.com/sharer/sharer.php?u=https%3A%2F%2Frealpython.com%2Flru-cache-python%2F
Get tips for asking good questionshttps://realpython.com/python-beginner-tips/#tip-9-ask-good-questions
get answers to common questions in our support portalhttps://support.realpython.com
Real Python Community Chathttps://realpython.com/community/
“Office Hours” Live Q&A Sessionhttps://realpython.com/office-hours/
intermediatehttps://realpython.com/tutorials/intermediate/
pythonhttps://realpython.com/tutorials/python/
Caching in Python With lru_cachehttps://realpython.com/courses/caching-python-lru/?utm_source=realpython&utm_medium=web&utm_campaign=related-course&utm_content=lru-cache-python
Primer on Python Decoratorshttps://realpython.com/primer-on-python-decorators/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=lru-cache-python
An Intro to Threading in Pythonhttps://realpython.com/intro-to-python-threading/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=lru-cache-python
Python's asyncio: A Hands-On Walkthroughhttps://realpython.com/async-io-python/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=lru-cache-python
Python's .__call__() Method: Creating Callable Instanceshttps://realpython.com/python-callable-instances/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=lru-cache-python
How to Use Redis With Pythonhttps://realpython.com/python-redis/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=lru-cache-python
https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Flru-cache-python%2F
Continue »https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Flru-cache-python%2F
Sign-Inhttps://realpython.com/account/login/?next=/lru-cache-python/
Start Herehttps://realpython.com/start-here/
Learning Resourceshttps://realpython.com/search
Code Mentorhttps://realpython.com/mentor/
Python Referencehttps://realpython.com/ref/
Python Cheat Sheethttps://realpython.com/cheatsheets/python/
Support Centerhttps://support.realpython.com/
Learning Pathshttps://realpython.com/learning-paths/
Quizzes & Exerciseshttps://realpython.com/quizzes/
Browse Topicshttps://realpython.com/tutorials/all/
Live Courseshttps://realpython.com/live/
Bookshttps://realpython.com/books/
Podcasthttps://realpython.com/podcasts/rpp/
Newsletterhttps://realpython.com/newsletter/
Community Chathttps://realpython.com/community/
Office Hourshttps://realpython.com/office-hours/
Learner Storieshttps://realpython.com/learner-stories/
Plans & Pricinghttps://realpython.com/account/join/
Team Planshttps://realpython.com/account/join-team/
For Businesshttps://realpython.com/account/join-team/inquiry/
For Schoolshttps://realpython.com/account/join-team/education-inquiry/
Reviewshttps://realpython.com/learner-stories/
About Ushttps://realpython.com/about/
Teamhttps://realpython.com/team/
Mission & Valueshttps://realpython.com/mission/
Editorial Guidelineshttps://realpython.com/editorial-guidelines/
Sponsorshipshttps://realpython.com/sponsorships/
Careershttps://realpython.workable.com
Press Kithttps://realpython.com/media-kit/
Merchhttps://realpython.com/merch
https://www.youtube.com/realpython
https://x.com/realpython
https://www.linkedin.com/company/realpython-com
https://www.facebook.com/LearnRealPython
https://github.com/realpython/
Privacy Policyhttps://realpython.com/privacy-policy/
Terms of Usehttps://realpython.com/terms/
Securityhttps://realpython.com/security/
Contacthttps://realpython.com/contact/
https://realpython.com/

Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover

Robots: max-image-preview:large


URLs of crawlers that visited me.