Closed dehzhas closed 5 years ago
@grosser I have made the recommended changes. Tests pass locally, but looks like Travis-CI is unable get the ruby environment setup properly to run the automated tests.
bumping in another PR worked, so I'd assume this is good to go too
1.9.0
Resolves issue https://github.com/rtomayko/rack-cache/issues/155 by warning once per class if purge isn't implemented.
A few notes:
I could not figure out a satisfactory way to truly warn on initialization in a backward compatible manner.
NotImplementedError
for a long time. It's really just the lookup method that needs resolution.NotImplementedError
in thelookup
. Anything more seems to imply some other architectural changes that would require more than a patch level version update so I went with this for now.I went with a simple
warn
call since that seems to be used elsewhere in the code.I'm not very familiar with MiniTest and googling around I wasn't able to figure out how to effectively ensure that
warn
was called exactly once per class. I left it at calling the method 2x and visually checking the warning only prints once. This makes me feel kinda icky though. I'm open to suggestions.The warn_once is not technically thread safe in the sense that there is a race condition where multiple threads could print a warning message if they check the key at the same time. I figured on occasional double warning is ok in this case rather than the overhead of dealing with a mutex.
I went with the simple
warn_once(key)
and building the message in a block rather than passing it to the method for performance reasons. Normally I'd consider this premature optimization, but since this is a performance boosting gem I thought paying attention here would be good. Let me know if you want to switch to just usingwarn_once(message)
.