Skip to content

Instantly share code, notes, and snippets.

@waicampos
Created March 1, 2024 13:20
Show Gist options
  • Save waicampos/54eeef751954a55db865979063383844 to your computer and use it in GitHub Desktop.
Save waicampos/54eeef751954a55db865979063383844 to your computer and use it in GitHub Desktop.
Exemplo de cache usando deque. Fonte: Canal Eduardo Mendes - Live de Python #28 Deque e Namedtuple / Collections #1
from collections import deque
cache_values = deque(maxlen=3)
def cache(func):
def inner(*args):
cache_values.append(args)
return func(*args)
return inner
@cache
def soma(x, y):
return x + y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment