rails/rails — Issue #3778: Rails.cache.fetch behaving inconsistently
Author: shyam-habarakada
Created: 2011-11-28 00:36:12+00:00
State: open

I'm trying to get memcached working with rails 3.0.9 and ruby 1.9.3, and the following code running inside a controller produces inconsistent results. Essentially, the fetch method is returning an Array when there is a cache miss and a String when there is a cache hit.

```ruby
@the_results = Rails.cache.fetch("a_key") do
TheModel.all
end

logger.info("@the_results.class = #{@the_results.class}")
```

This seems to occur when I have `config.cache_classes = false` (in the development environment). Turning on cache_classes fixes the issue, but I don't want that in development.

Here is my cache configuration

```ruby
memcache_options = {
:compression => false,
:debug => true,
# :namespace => 'default',
:readonly => false,
:urlencode => false
}

memcache_servers = "localhost"

config.cache_store = :mem_cache_store, memcache_servers, memcache_options
```

Is this a known issue? I found some related tickets that are closed, but they didn't look exactly the same.