grosser / cachy

Ruby: Caching library to simplify and organize caching
44 stars 8 forks source link

expires_in does not work with Moneta cache store #7

Open rajatjindal opened 8 years ago

rajatjindal commented 8 years ago

It seems like Cachy does not expire the cache even after timeout (or may be I am using it incorrectly).

Look at this test that I added to existing tests for Cachy using Moneta cache store which is failing.

https://github.com/rajatjindal83/cachy/commit/8f1bde65d32088eae2e54036578f3f1b3163d185

Your feedback will be highly appreciated.

It fails as follows:

C02PRUQFG8WP:cachy rjindal$ rake rspec spec/ ...............F.........................................*.................

Pending: Cachy key_versions merges in old when setting new

!!!!!

# ./spec/cachy_spec.rb:275

Failures:

1) Cachy::MonetaWrapper expires on timeout Failure/Error: Cachy.cache(:timeout_key) { 'newkey' }.should_not == 'original' expected not: == "original" got: "original"

./spec/cachy/moneta_wrapper_spec.rb:63:in `block (2 levels) in <top (required)>'

Finished in 3.14 seconds 75 examples, 1 failure, 1 pending

Failed examples:

rspec ./spec/cachy/moneta_wrapper_spec.rb:60 # Cachy::MonetaWrapper expires on timeout

grosser commented 8 years ago

it passes the expires_in option to the backend ... https://github.com/grosser/cachy/blob/master/lib/cachy.rb#L29 ...https://github.com/grosser/cachy/blob/master/lib/cachy/moneta_wrapper.rb#L6 so nothing it can do after that point if the backend does not support it ... maybe the backend needs a differently named option ... check the moneta spec / see if you can get it to work by directly using moneta and then somehow make a PR for cachy ...

jxc876 commented 8 years ago

I noticed the same thing :expires_in doesn't expire with the Memory store. I got the expiration to work by setting the timeout when I'm creating the Moneta store but its a global expiration (global behaviour was ok for my use case, but an individual :expires_in option would be better):

Moneta.new(:LRUHash, expires: 30)

https://github.com/minad/moneta/issues/96