Skip to content

[feature] cached_result dynamic key generation #45

@Mark90

Description

@Mark90

Background

The cached_result() decorator can generate dynamic keys for caching data in Redis.

Applying that decorator to a function which takes complex types/objects would generate cache keys containing memory addresses, effectively negating the effect of the caching (and filling up Redis as a bonus).

This has been partially addressed in #46 by

  1. Stripping the self argument from the cache key, in case the decorator is applied to an instance method
  2. Checking the decorated function's signature for unsafe types and warning the user

In the long term we may want to improve this, if there's a usecase for it. So please leave a comment with your findings.

Feature improvements

  • Add types.py from orchestrator-core (and add tests etc) to nwa-stdlib to improve unsafe types detection/warning
  • Change cached_result() to accept a callable for users to override dynamic key generation

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions