TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ring: Advanced cache interface for Python

174 pointsby youknowonealmost 6 years ago

13 comments

suvelxalmost 6 years ago
Every example seems to follow this pattern<p><pre><code> client = pymemcache.client.Client((&#x27;127.0.0.1&#x27;, 11211)) #2 create a client # save to memcache client, expire in 60 seconds. @ring.memcache(client, expire=60) #3 lru -&gt; memcache def get_url(url): return requests.get(url).content </code></pre> How are you supposed to configure the client at &#x27;runtime&#x27; instead of &#x27;compile time&#x27; (when the code is executed and not when it&#x27;s imported)?<p>Careful placement of imports in order to correctly configure something just introduces delicate pain points. It&#x27;ll work now, but an absent minded import somewhere else later can easily lead to hours of debugging.
评论 #20030525 未加载
评论 #20030621 未加载
评论 #20030042 未加载
评论 #20031085 未加载
评论 #20035361 未加载
评论 #20034625 未加载
coleiferalmost 6 years ago
Extremely poor design:<p>* Not DRY. What if I want to use a cache for production but disable caching in development? And I have 10s or even 100s of functions that rely on the cache? Because the decorators contain implementation&#x2F;client-specific parameters, I now have to add another entire layer of abstraction over this.<p>* Implementation is tied to the decorator, e.g. `ring.memcache` -- seriously? Why does it matter?<p>* What about setting application defaults, such as an encoding scheme, a key prefix&#x2F;namespace, a default timeout?<p>I&#x27;m sorry but this is over-engineered garbage and good luck to anyone who uses it.
评论 #20033179 未加载
评论 #20034957 未加载
tyingqalmost 6 years ago
Is there a python equivalent to php&#x27;s apcu? Apcu, in the PHP world, leverages mmap to provide a multi-process kv store, with fast, built in serialization. So it&#x27;s simple and very fast for single server, multi-process caching.
评论 #20029886 未加载
kristoff_italmost 6 years ago
Great project. There is only one angle that I feel is missing: multiple requests for the same resource could cause duplicated work, especially if the value generating function is slow.<p>I wrote a sample solution to that problem, feel free to reach out if you ever consider adding a similar feature, I&#x27;d be happy to contribute. (fyi: the current implementation is in Go)<p><a href="https:&#x2F;&#x2F;github.com&#x2F;kristoff-it&#x2F;redis-memolock" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kristoff-it&#x2F;redis-memolock</a>
评论 #20030282 未加载
bsdzalmost 6 years ago
Looks extensive and I&#x27;ll likely try using the module at some point.<p>One thing, why not stash all the function methods under a &quot;ring&quot; or &quot;cache&quot; attribute, eg<p><pre><code> @ring.lru() def foo() .. foo.cache.update() foo.cache.delete() .. </code></pre> This might be less likely to clash with any existing function attributes (if you&#x27;re wrapping a 3rd party function say).
评论 #20030364 未加载
mrlinxalmost 6 years ago
Like this a lot.<p>How could only invalidate everything related to a specific client&#x2F;customer&#x2F;account?<p>I wonder how they cascade these invalidations at bigger and more complex systems.
评论 #20029394 未加载
ergo14almost 6 years ago
The api doesn&#x27;t seem to be fleshed out compared to dogpile.cache yet.<p>Normally you don&#x27;t want to pass cache backend instance to decorators on module level.
评论 #20032596 未加载
TeeWEEalmost 6 years ago
How does this compare to dogpile?
评论 #20029302 未加载
评论 #20031200 未加载
mychaelalmost 6 years ago
&gt;Cache is a popular concept widely spread on the broad range of computer science but its interface is not well developed yet.<p>This sentence is grammatically incorrect. Replace &quot;Cache&quot; with Caching&quot;.
评论 #20033194 未加载
alexeizalmost 6 years ago
I needed something like this that allows access to and manual manipulation of the cache, and I ended up forking functools.lru_cache code. This library definitely fits the bill.
tomnipotentalmost 6 years ago
&gt; Memcached itself is out of the Python world<p>Don&#x27;t know why this bothers me so much... but it&#x27;s actually from Perl. It was born at LiveJournal, a well-known Perl shop.
评论 #20032333 未加载
merlincoreyalmost 6 years ago
To me, mocking of the caches for testing is super important and missing.<p>I searched the article, the linked &quot;Why Ring?&quot;, and this page of responses for &quot;mock&quot;, but no results.<p>Maybe it&#x27;s just me!
评论 #20033415 未加载
Dowwiealmost 6 years ago
no dogpile lock support?
评论 #20032368 未加载