Feature request: Create a dedicated Cache utility in Powertools (based on current idempotency layer)

Aperta
#7,069 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
aws, python

Direzione di ricerca

Start by reading the existing Idempotency utility and its storage provider classes, especially the DynamoDB persistence layer referenced in the example. The proposed entry point is aws_lambda_powertools.utilities.caching with Cache, DynamoDBPersistenceLayer, get, and set; determine whether existing storage behavior can be generalized without idempotency-specific record handling. Done means the new cache API, persistence integration, TTL behavior, and relevant tests match the requested example.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

feature-request
Use case

Customers are using the Powertools Idempotency utility for caching purposes. Idempotency is a specific implementation that includes a "caching" mechanism via the storage provider classes. Idempotency is a particular use case, and there is inbuilt functionality for dealing with the records in a specific way which I feel is dangerous for caching use cases.

Solution/User Experience

from aws_lambda_powertools.utilities.caching import (
    DynamoDBPersistenceLayer,
    Cache,
)

table = os.getenv("CACHE_TABLE", "")
persistence_layer = DynamoDBPersistenceLayer(table_name=table)
cache =  Cache(persistence_store=peristsance_layer)
my_ttl = 300

def lambda_handler(event: dict, context: LambdaContext):
    try:
        previous_value = cache.get(event.order_id, "default_value")

        payment: Payment = create_subscription_payment(event, previous_value)

        cache.set(order_id, payment.detail, my_ttl)

        return {
            "payment_id": payment.payment_id,
            "message": "success",
            "statusCode": 200,
        }
    except Exception as exc:
        raise PaymentError(f"Error creating payment {str(exc)}")


def create_subscription_payment(event: dict) -> Payment:
    return Payment(**event)


Alternative solutions

Acknowledgment
Lingua principale
Python
Stelle
3.3k
Fork
511
Merge medio
3g 8h
PR unite (30g)
92

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di aws-powertools/powertools-lambda-python

Tutte le issue di aws-powertools/powertools-lambda-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.