简体   繁体   English

Rails 4,印象派和counter_cache

[英]Rails 4, Impressionist and counter_cache

I have a Post model which I've made impressionable : 我有一个Post模型,使我印象深刻

is_impressionable :counter_cache => true, :column_name => :views

I was thinking about, let's say once a month, clearing impressions older than a given period. 我当时在想,比如说每月一次,清除比给定时间更长的印象。 Would this somehow reset the counters cache in the posts table too ? 这会以某种方式重置发帖表中的计数器缓存吗? In this case, is there any solution ( increment only counter cache ? ) to avoid the impressions table growing bigger and bigger until it goes out of control without resetting the counters ? 在这种情况下,是否有解决方案(仅增加计数器缓存?),以避免印象表变得越来越大,直到失去控制而不重置计数器?

Thanks 谢谢

You cannot remove impressions from the impressions table, because every time the cache needs to be updated, impressionist will actually recount all the impressions (filtered by the unique option you're providing is_impressionable ). 您不能从印象表中删除印象,因为每次需要更新缓存时,印象派实际上都会重新计算所有印象(由您提供的is_impressionable唯一选项过滤)。

I'm not sure what you can do with the gem to achieve what you want, except patching it, or managing the counter_cache yourself. 我不确定您可以使用gem来实现所需的功能,除了修补它或自己管理counter_cache之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM