removing items from cache not working

57 views
Skip to first unread message

Alex

unread,
Dec 15, 2014, 6:22:38 PM12/15/14
to web...@googlegroups.com

I've got a function which returns a dict with some values. the function has this decorator:

@cache('admin.setting.limits', 3600, cache.ram)

def get_limits():

..


This works fine and the values are used from cache. When I change those settings I want to clear the cache so I'm doing this:

cache.ram.clear(regex='admin\.setting.*')

When I call my function again the cached values are still used. Am I doing something wrong here? Any ideas?


regards,

Alex

Derek

unread,
Dec 15, 2014, 6:58:38 PM12/15/14
to web...@googlegroups.com
Why are you not just clearing the exact key?

cache.ram('admin.setting.limits',None)

Alex

unread,
Dec 15, 2014, 7:18:31 PM12/15/14
to web...@googlegroups.com
because I have multiple values cached in different functions and all can be edited on the same page. I'll test to delete it with the exact key. Anything wrong with the regex?

Alex

unread,
Dec 15, 2014, 7:22:40 PM12/15/14
to web...@googlegroups.com

tested with clearing values with exact key and this seems to work. Do you know why using the regex doesn't work?


Alex

Derek

unread,
Dec 15, 2014, 7:32:01 PM12/15/14
to web...@googlegroups.com
Your regex is wrong then.

try this?

admin\.setting\.[A-z]*

Alex

unread,
Dec 15, 2014, 7:40:55 PM12/15/14
to

the regex should be fine (I tested it with a regex online tool). Doesn't make a difference if I use your regex.

Thanks for your help, I can fix the problem by clearing the exact values. But I'd still like to understand what's wrong with clearing the cache by regex.

Anthony

unread,
Dec 15, 2014, 8:51:07 PM12/15/14
to web...@googlegroups.com
How about:

cache.ram.clear(regex=r'admin\.setting.*')

Anthony

Alex

unread,
Dec 16, 2014, 6:04:18 AM12/16/14
to web...@googlegroups.com

That would make sense. But it's still the same result. I've changed my cache keys to avoid dots and only use underscore instead:

adminsetting_limits

and now I can delete the cached values without any problems:

cache.ram.clear(regex=r'adminsetting.*')


I still don't fully understand why the original regex doesn't work but at least it's not an issue anymore.

Alex

unread,
Dec 16, 2014, 6:51:38 AM12/16/14
to web...@googlegroups.com
seems like this is related to a change in web2py. Until recently I used web2py 2.4.6 and I never had a problem - I just tested it again. In 2.4.6 the original regex works. After I upgraded to 2.9.11 the regex doesn't work anymore.

Paolo Valleri

unread,
Dec 16, 2014, 7:11:25 AM12/16/14
to web...@googlegroups.com
Hi Alex, I think this is the commit you are looking for https://github.com/web2py/web2py/commit/0dbdf8c676547071d608f800f72d7c3d0aa6ebda
Only the first element matching the regex is deleted.
I'd revert that commit, and it'd be nice to add a test to better check that issue

Paolo

Alex

unread,
Dec 16, 2014, 7:43:46 AM12/16/14
to
 exactly, that's the issue. Now it makes sense why it worked on very rare occasions. A test for this use case would be a good idea. here is the code in 2.4.6 which runs fine:
        r = re.compile(regex)
       
for (key, value) in storage.items():
           
if r.match(str(key)):
               
del storage[key]

and this is the code from 2.9.11 which fails:
        r = re.compile(regex)
       
for key in storage:
           
if r.match(str(key)):
               
del storage[key]
               
break

should I open a bug report or can someone directly fix it?

btw, changing the cache keys to avoid dots (as mentioned above) therefor only worked because I only had one cached value for testing.

Alex

Paolo Valleri

unread,
Dec 16, 2014, 8:19:16 AM12/16/14
to web...@googlegroups.com

I will fix it later today

On Dec 16, 2014 1:43 PM, "Alex" <mrau...@gmail.com> wrote:
 exactly, that's the issue. Now it makes sense why it worked on very rare occasions. A test for this use case would be a good idea. here is the code in 2.4.6 which runs fine:
        r = re.compile(regex)
       
for (key, value) in storage.items():
           
if r.match(str(key)):
               
del storage[key]

and this is the code from 2.9.11 which fails:
        r = re.compile(regex)
       
for key in storage:
           
if r.match(str(key)):
               
del storage[key]
               
break

should I open a bug report or can someone directly fix it?

Alex

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/72vUKgyDkxQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages