mongodb_beaker icon indicating copy to clipboard operation
mongodb_beaker copied to clipboard

Patch suggestion for dotted keys

Open gravi2 opened this issue 13 years ago • 1 comments

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"

gravi2 avatar Dec 21 '11 04:12 gravi2

Please email me at [email protected], if you have any questions about the above suggestions

gravi2 avatar Dec 21 '11 05:12 gravi2