-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cleanup block to FastCache::Cache, with RSpec tests. #3
base: master
Are you sure you want to change the base?
Conversation
@@ -39,6 +39,7 @@ def initialize(max_size, ttl, expire_interval = 100) | |||
@op_count = 0 | |||
@data = {} | |||
@expires_at = {} | |||
@cleanup = Proc.new if block_given? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Quality Gate passedIssues Measures |
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: