bwmcadams/mongodb_beaker — Issue #4: Patch suggestion for dotted keys
Author: gravi2
Created: 2011-12-21 04:56:32+00:00
State: open

Short version : This will patch addresses the issue where the beaker keys may contain dots.

Long version:
I have used your library as a beaker cache and learned that when a function is decorated with beaker and if any of the parameters passed to this function has dots, the cache does not work.

Example:
@cache_region('short_term')
def some_function(value1):
....
....
return some_computed_value

if in the above function the value1 is passed as "some.dotted.string" the cache on this function does not work. This is because the "key" for the above function will be:
"some_function some.dotted.string"

Mongodb interprets the above key and store it something as:
{some_function some: { dotted : { string : .....}

As such the passed key and stored keys never match and cache fails.

Suggested Patch/Fix:

1) Add the Following function:
def __format_key__(self,key):
return re.sub(r'[\s]+',' ',key).replace(' ',':').replace('.',':')
2) Call it in every function that deals with keys e.g:
__contains__
set_value
__get_item__
__delitem__

The above essentially, converts the key as follows:
"some_function some.dotted.string" => "some_function:some:dotted:string"