I am trying to expire key in 10 seconds, somehow it is, but not working with rspec. In this process, I noticed Rails.cache.write
return false
in Rails 2.3.11, while Rails.cache.write
return true
in Rails 3.2.11, is this a problem? why different value? Why Rails 2.3.11 return false
and Rails 3.2.11
return true
?
Rails 2.3.11
irb(main):001:0> Rails.cache.write("test", "java", :expires_in => 10.seconds)
=> false
Rails 3.2.11
irb(main):001:0> Rails.cache.write("test", "java", :expires_in => 10.seconds)
=> true
I am using jruby 1.6.5.1 with Rails 2.3.11 and jruby 1.7.3 with Rails 3.2.11.
The Rails.cache.write
method is what is sometimes known as a command method, which is called for its side effects, as opposed to a query method, called for its return value (for more info, check out command-query separation).
Since the Rails docs make no guarantees about the return value, it is probably best not to depend on it, since it might (and apparently has) change without warning.