Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3976482
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:48:36+00:00 2026-05-20T04:48:36+00:00

What I want to do is to mark some values in the cache as

  • 0

What I want to do is to mark some values in the cache as related so I could delete them at once. For example when I insert a new entry to the database I want to delete everything in the cache which was based on the old values in database.

I could always use cache.clear() but it seems too brutal to me. Or I could store related values together in the dictionary and cache this dictionary. Or I could maintain some kind of index in an extra field in cache. But everything seems to complicated to me (eventually slow?).

What you think? Is there any existing solution? Or is my approach wrong? Thanks for answers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:48:37+00:00Added an answer on May 20, 2026 at 4:48 am

    Are you using the cache api? It sounds like it.

    This post, which pointed me to these slides helped me create a nice generational caching system which let me create the hierarchy I wanted.

    In short, you store a generation key (such as group) in your cache and incorporate the value stored into your key creation function so that you can invalidate a whole set of keys at once.

    With this basic concept you could create highly complex hierarchies or just a simple group system.

    For example:

    class Cache(object):
        def generate_cache_key(self, key, group=None):
            """
            Generate a cache key relating them via an outside source (group)
            Generates key such as 'group-1:KEY-your-key-here'
    
            Note: consider this pseudo code and definitely incomplete code.
            """
            key_fragments = [('key', key)]
    
            if group:
                key_fragments.append((group, cache.get(group, '1')))
    
            combined_key = ":".join(['%s-%s' % (name, value) for name, value in key_fragments)
    
            hashed_key = md5(combined_key).hexdigest()
            return hashed_key
    
    
        def increment_group(self, group):
            """
            Invalidate an entire group
            """
            cache.incr(group)
    
    
        def set(self, key, value, group=None):
            key = self.generate_cache_key(key, group)
            cache.set(key, value)
    
    
        def get(self, key, group=None):
            key = self.generate_cache_key(key, group)
            return cache.get(key)
    
    # example
    >>> cache = Cache()
    >>> cache.set('key', 'value', 'somehow_related')
    >>> cache.set('key2', 'value2', 'somehow_related')
    >>> cache.increment_group('somehow_related')
    >>> cache.get('key') # both invalidated
    >>> cache.get('key2') # both invalidated
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site I'm working on where I want to mark if a
Definitions lists are a great way to mark up information where some key word
I have some 34 checkboxes on one Activity which i have to mark and
If all tables I want to delete from have the column gamer_id can i
Want to know what the stackoverflow community feels about the various free and non-free
Want my FireFox at work to be in sync with my FireFox at my
I want to loop over the contents of a text file and do a
I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal
I want to create a Java application bundle for Mac without using Mac. According
I want to create a client side mail creator web page. I know the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.