Add cleanup block to FastCache::Cache, with RSpec tests.#3
Add cleanup block to FastCache::Cache, with RSpec tests.#3joelnordell wants to merge 3 commits intoswoop-inc:masterfrom
Conversation
lib/fast_cache/cache.rb
Outdated
There was a problem hiding this comment.
Please provide the block as an ¶m. This type of defaulting is one of the obscure features of Ruby that saves a few characters at the expense of readability.
|
A high level question about this PR: does it make sense to add the cleanup behavior to a simple fast cache? If the use case is to cache connections, of which there typically are not many, and which do slow I/O, does it matter whether the cache is fast or slow? |
|
Good comments -- I'll push another commit that addresses them. Regarding the high level question: my use case is actually not caching slow things like connections, but caching allocated data structures for a native library (via FFI) which contain open file descriptors that need to be manually cleared/closed. I'm using FastCache not only for its speed, but also for its convenient API and the ability to specify both a maximum size and a time-to-live. |
fcae2ac to
e4feb40
Compare
|



This allows the user to specify a block to be called whenever an object is removed from the cache, to perform some cleanup action on it:
Example usage scenario -- caching connections that should be closed upon removal from the cache: