2

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.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
AMIC MING
  • 6,306
  • 6
  • 46
  • 62
  • Check this http://stackoverflow.com/questions/6500142/rails-cache-read-returns-nil-in-rails-but-not-in-console – CodeGroover Jun 07 '13 at 17:44
  • @CodeGroover - that's not solved my problem, I checked if I make it config.cache_classes true, doesn't change my output that I placed in question – AMIC MING Jun 07 '13 at 17:51
  • i'm sure that problem in env diff. – CodeGroover Jun 07 '13 at 18:10
  • @CodeGroover if I make it config.cache_classes true for Rails 2.3.11 and restart console, I am not seeing any difference, same apply for Rails 3.2.11 – AMIC MING Jun 07 '13 at 18:14

1 Answers1

6

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.

Wally Altman
  • 3,535
  • 3
  • 25
  • 33