-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
When I upgraded Mongoid from 3.1.4 to 3.1.6。I use Query::Cache Middleware to cache my query。 But I find that the cache has same problem.
For examle:
def index @users = UserMongo.all end
At the other place(maybe index view), I will use @users
if @users.present? #----> flag_A ...other operations @users.each do |p| #-----> flag_B .... end end
When the program go to 'flag_B', then it will raise one execption:
QUERY CACHE database=tianji collection=users selector={} TypeError: no implicit conversion of String into Integer from /home/andy/Documents/mongoid/lib/mongoid/factory.rb:40:in `[]'
and the source about cache as follow:
module Mongoid module QueryCache module Cacheable def with_cache return yield unless QueryCache.enabled? return yield if system_collection? key = cache_key if QueryCache.cache_table.has_key?(key) instrument(key) { QueryCache.cache_table[key] } else value = yield QueryCache.cache_table[key] = value end end end end def cache_key [ operation.database, operation.collection, operation.selector ] end
after debug the source code, I find that at 'flag_A', @users.present?, QueryCache.cache_table[key] has be set:
puts QueryCache.cache_table -->
{["tianji", "users", {}]=>{"_id"=>158}}
So when go to flag_B, It will raise error!!!
My Point
I think that it is cache key is not clear to flag one query.
So guys, do you match same problem?