samsaffron / lru_redux Goto Github PK
View Code? Open in Web Editor NEWAn efficient optionally thread safe LRU Cache
License: MIT License
An efficient optionally thread safe LRU Cache
License: MIT License
With the addition of a new cache I wanted to get some feedback on the current working name for the TTL cache. I also included an alternative naming scheme to consider.
# Current
LruRedux::Cache
LruRedux::ThreadSafeCache
# Working TTL names
LruRedux::TtlCache
LruRedux::ThreadSafeTtlCache
# Alternative
LruRedux::LRU::Cache
LruRedux::LRU::ThreadSafeCache
LruRedux::TTL::Cache
LruRedux::TTL::ThreadSafeCache
If the modularized name space was chosen, the current namespaces LruRedux::Cache
and LruRedux::ThreadSafeCache
could be made into a subclass to provide identical functionality (and backwards compatibility) but also raise a warning about the name change. This is similar to what the 'minitest' gem does if you call MiniTest::Unit::TestCase
instead of MiniTest::Test
.
Hi Sam, granted this isn't the best use an a "issue" but i'm wondering if you have an example of how you use this gem with discourse?
I've seen your presentation Off The Rails https://www.youtube.com/watch?v=aP5NNkzb4og but didn't really follow what the benefit of using LRU Cache is in web apps.
Do you have a simple example of where this could be most commonly used?
Thanks
Tim
cache.each {|k,v| p "#{k} #{v}"}
NoMethodError: undefined method `reverse' for {:b=>"2"}:Hash
An alternative would be:
Hash[@data.to_a.reverse]
Ruby Version: 2.0.0p247
Is there a reasonable mechanism for monitoring the cache hit ratio of any of the lru_redux
caches? I can of course, monitor using booleans etc at the callsite, but it's kinda inconvenient if there are plenty of them.
Would you be interested in a patch that adds stats somehow?
Hi, I was just wondering if there were plans to add an equivalent to the soft_ttl functionality from lrucache, or forced expiry on a timer?
My app hits another server for results which change semi-frequently. I'm caching the results for 30 seconds, but I frequently don't fill the cache to the point things get evicted so they just sit there forever. I'm aware I could have a thread call .expire!
every so often, but ideally I'd like to make entries expire when they've been there for a certain amount of time (i.e. force retrieval without them being evicted).
Is there any means for executing a callback (lambda/proc/block) when an item is automatically evicted from the cache due to cache size? This is useful in scenarios where necessary cleanup has to occur before dereferencing an object, such as for network connection related matters.
cache.getset(:foo, ignore_nil: true) { nil }
cache.key?(:foo) == false
cache[:foo] == nil
cache.getset(:foo, ignore_nil: true) { :bar }
cache.key?(:foo) == true
cache[:foo] == :bar
The LruRedux::TTL::ThreadSafeCache.delete
method does not return the deleted item as docs say. It looks like the code returns an expiration time float value and not the deleted item.
Easy enough to work around, but we need to either update the README docs or change the library's behavior.
Example reproduction:
my_cache = LruRedux::TTL::ThreadSafeCache.new(8, 300)
my_cache["a"] = "This is string A"
my_cache["b"] = "This is string B"
result_obj = my_cache.delete "a"
puts "result_obj: #{result_obj} #{result_obj.class}"
This produces output like:
result_obj: 1697043228.1882849 Float
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.