flask-cache icon indicating copy to clipboard operation
flask-cache copied to clipboard

return value of proxy functions

Open cutewalker opened this issue 9 years ago • 0 comments

for the proxy functions as following

  • Cache.set
  • Cache.add
  • Cache.delete
  • Cache.delete_many
  • Cache.clear
  • Cache.set_many

the return value is always None. but we sometimes really need the return value of the internal cache object 's operations. for example, we can use memcache.add as a distributed lock to guarantee atomic operations:

if memcache.add(key, value):
    do_something_exclusively
else:
    # someone else is doing the same thing
    pass

but without the retuen value, we have to use cache.cache.add.

So, would you consider this and change the proxy functions like this:

     def add(self, *args, **kwargs):
         "Proxy function for internal cache object."
-        self.cache.add(*args, **kwargs)
+        return self.cache.add(*args, **kwargs)

or is there some other reason to keep discarding interal operation's return value ?

cutewalker avatar Feb 24 '16 07:02 cutewalker