Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to efficiently retrieve keys by tag #341

Open
BoPeng opened this issue Feb 11, 2025 · 0 comments
Open

Unable to efficiently retrieve keys by tag #341

BoPeng opened this issue Feb 11, 2025 · 0 comments

Comments

@BoPeng
Copy link

BoPeng commented Feb 11, 2025

I have a number of keys organized by tags and would like to get a list of keys with a certain tag. However, I cannot find a straightforward way to do this.

Current workaround:

for key in cache.iterkeys():
    if cache.get(key, tag=True)[-1] == 'counter':
        # ...

This approach is awkward and inefficient. It is of course possible to do

select = "SELECT key, raw, value FROM Cache WHERE tag = ?"
for key, raw, value in cache._sql(select, ('counter',))}:
        # get key, value from key and raw
        

but I would prefer not messing with the internal of diskcache

Proposed enhancement: It would be beneficial to add a tag parameter to the iterkeys method to allow:

    def iterkeys(self, reverse=False, tag=False):

This enhancement would simplify the code and improve efficiency when working with tagged keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant