sqlalchemy / sqlalchemy/dogpile.cache

Cache invalidation for class or instance methods

Open
#24 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
299
Forks
50
PR merge metrics
No merged PRs in 30d

Description

Migrated issue, originally created by David Beitey (davidjb)

When attempting to invalidate or set a value for a class or instance method that's being cached via CacheRegion.cache_on_arguments, the first argument passed to the decorated function's invalidate or set methods is ignored. For example, if I have

#!python

class Foo(object):

    @cache.cache_on_arguments()
    def do_something(self, text):
        return text + 'dummy'

then if one wants to clear or set the cache for this method, they need to do this:

#!python

foo = Foo()
cached = foo.do_something('asdf')
foo.do_something.invalidate(anything_goes, 'asdf')
foo.do_something.set('value', anything_goes, 'asdf')

as the first argument passed into either function is ignored as part of the cache key.
This is probably expected behaviour for now, but I think the situation should be documented either way.

Since the first argument going into those invalidate/set is ignored regardless by the key generator, I think it would be easier to have the key generator use all arguments if the decorated method belongs to a class or instance. This would be far less prone to error as I've found when trying to clear such a cached method & forgetting the first argument.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with CacheRegion.cache_on_arguments and trace how its key generator handles decorated class and instance methods, then review the issue discussion before choosing between documentation and changed behavior. Done means the selected behavior is clearly documented, or the revised key handling is covered by tests for invalidate and set.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.