Auto-select an available backend

Issue #93 resolved
Mark V
created an issue

Sorry if this is somehow obvious but I can't find it. Does dogpile.cache have any way to choose a backend automatically (e.g. by trying them from fast to slow until one works)?

I want to use it in some code that many people can use and customize and would like to minimize the setup that is strictly necessary for them.

Of course then the code should only use the shared functionality like get, set, delete and cache_on_arguments but that seems useful enough.

If it doesn't exist, would that be something you'd want to include if someone made it? (I'm not promising). And do you have any pointer on where to implement it? Make a special backend for it that just proxies all requests to the first working other backend it finds?

Comments (5)

  1. Michael Bayer repo owner

    how would such a backend "auto select" between a Memcached backend that's on one particular IP number and a Redis clustered backend that's on another? Which one of those is "faster"?

    I'd recommend if you have some backends in mind you can perhaps build such a routine for your own use using ProxyBackend but I don't see how such a thing could be generalized.

  2. Mark V reporter

    That's a good point, I was only thinking of services running on the local machine, it won't work if the connection parameters can't be determined by default. Local is good enough for me so I might make it for myself only then. I don't really know how common it is to have a cache server that's not reachable with default parameters (non-local or such), so I don't know if this makes it useless for most people.

    As for which is faster, it'd just be about general trends (memcached/pylibmc faster than file based cache). I don't think that one is a problem: if a user has a file cache that is faster than pylibmc and cares enough, he can specify that backend, while most people won't need to.

    So I'll mark the issue as resolved then, and maybe post a reply when it's done, if I remember.

  3. Mark V reporter

    Okay I made a function that checks backends and chooses one it can find. Since it's mostly for personal use, I just made a function instead of using ProxyBackend. It's public domain in case you want to use any part of it. You can find it here. It seems quite useful :-)

  4. Log in to comment