SlideServe
Menu
Préférences
© SlideServe · v2026

Caching in Python

Sudhanshi avatar
6 diapositives · 81 Views · Aug 03, 2023

https:\/\/pythongeeks.org\/caching-in-python\/

Caching in Python - slide 1
01 / 6Caching in Python
1 / 17

Télécharger la présentation

Caching in Python
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. CACHING IN PYTHON pythongeeks

  2. CACHING IN PYTHON Caching is a powerful technique to improve the performance of a software system by storing frequently accessed data in a temporary location. Caching in Python can be implemented using various strategies such as LRU Cache, MRU Cache, etc. In this blog, we will focus on the LRU Cache strategy. LRU (Least Recently Used) Cache is a technique used for caching where the least recently used items are removed from the cache to make room for new items. Python provides an LRU Cache implementation as a part of the functools module.

  3. ADVANTAGES OF LRU CACHE: Improved performance due to the presence of frequently accessed data in the cache Reduced latency as the data is retrieved from the cache instead of the slower data source Reduced resource utilization as the frequently accessed data is stored in the cache and the expensive computations are not performed multiple times.

  4. DISADVANTAGES OF LRU CACHE: Increased memory usage due to the presence of cached data Stale data in the cache can lead to incorrect results if the cache is not invalidated in a timely manner Cache eviction policies can lead to cache thrashing if not chosen carefully.

  5. HOW TO IMPLEMENT LRU CACHE IN PYTHON: Python provides an LRU Cache implementation as a part of the functools module. The LRU Cache can be created using the ‘functools.lru_cache()’ decorator. Here’s an example of how to implement LRU Cache using the ‘functools.lru_cache()’ decorator: import functools @functools.lru_cache(maxsize=128) def expensive_function(arg): # Perform some expensive computation return result

  6. CONCLUSION Caching is a powerful technique to improve the performance of a software system. LRU Cache is a popular caching strategy used in Python that helps in improving the performance of the system by storing frequently accessed data in a cache. Python provides an LRU Cache implementation as a part of the functools module, making it easy to implement and use. By understanding the advantages and disadvantages of LRU Cache, developers can make informed decisions on whether to use this caching strategy in their Python applications.