|
|
|
|
|
by suvelx
2575 days ago
|
|
Every example seems to follow this pattern client = pymemcache.client.Client(('127.0.0.1', 11211)) #2 create a client
# save to memcache client, expire in 60 seconds.
@ring.memcache(client, expire=60) #3 lru -> memcache
def get_url(url):
return requests.get(url).content
How are you supposed to configure the client at 'runtime' instead of 'compile time' (when the code is executed and not when it's imported)?Careful placement of imports in order to correctly configure something just introduces delicate pain points. It'll work now, but an absent minded import somewhere else later can easily lead to hours of debugging. |
|
You are then welcome to instantiate your ring.memcache object and bind it were it pleases you.
I would have provided a different API though:
And accepted the alternative: It's better to not expect all people to know about the details of decorators just to use your API, and a factory is a nice hook to have anyway: it say where the code for that dynamic configuration should be and code as documentation is the best doc.Also a patch() context manager would be nice for temporary caching:
But it's hard to do in a thread safe way to compromised would have to be made.