May 29, 2023, 11:19 a.m. | Maxime Guilbert

DEV Community dev.to

Quand on bosse sur des apis, notamment pour visualiser des informations, ça arrive rapidement qu'on ait plein d'appels identiques. Du coup, pour éviter une surutilisation inutile de nos ressources on peut mettre en place un cache directement dans notre api en Python.


Donc aujourd'hui, on va voir comment faire ça avec lru_cache.





Installation


Comme beaucoup de librairie python, lru_cache est disponible via pip.


PIP - Lru_cache : https://pypi.org/project/lru_cache/



pip install lru_cache





Utilisation



from cache import LruCache  

@LruCache( …

api apis beginners des french python tutorial

Data Engineer

@ Lemon.io | Remote: Europe, LATAM, Canada, UK, Asia, Oceania

Artificial Intelligence – Bioinformatic Expert

@ University of Texas Medical Branch | Galveston, TX

Lead Developer (AI)

@ Cere Network | San Francisco, US

Research Engineer

@ Allora Labs | Remote

Ecosystem Manager

@ Allora Labs | Remote

Founding AI Engineer, Agents

@ Occam AI | New York