-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
This ticket has now been changed to deprecate the use of the criteria cache. The Mongoid::QueryCache is more effective in caching queries and all caching functionality should be delegated there.
Original ticket:
===========
Mongo context has this usage of try_cache for example:
def count(options = {}, &block) return super(&block) if block_given? try_cache(:count) { view.count_documents(options) } end
This seems to imply that the options to count aren't part of the cache key. However count can be limited, suggesting that if I call count with limit 1 and then count with no limit I may receive wrong result (count=1 instead of actual count).
To reproduce this, criteria must be explicitly cached:
irb(main):026:0> c = Band.all => #<Mongoid::Criteria ... irb(main):027:0> cc = c.cache => #<Mongoid::Criteria ... irb(main):028:0> cc.count(limit: 4) => 4 irb(main):029:0> cc.count(limit: 5) => 4
To fix this, try_cache calls must pass in options applicable to the query in each invocation, for example limit in the case of count above.
- clones
-
MONGOID-5414 Remove criteria/contextual caching
- Closed