1
我们在我们的应用程序中使用活动管理员。我有大量的数据等待管理。我想在活动管理中实现页面缓存/操作缓存,并希望在我的特定调用中过期片段。我不介意在索引页面上显示一段时间的陈旧数据。有人能给我提供一些基本的例子,说明如何在活动管理中实现page_caching/action_caching?如何在活动管理员中实现页面缓存或动作缓存
我们在我们的应用程序中使用活动管理员。我有大量的数据等待管理。我想在活动管理中实现页面缓存/操作缓存,并希望在我的特定调用中过期片段。我不介意在索引页面上显示一段时间的陈旧数据。有人能给我提供一些基本的例子,说明如何在活动管理中实现page_caching/action_caching?如何在活动管理员中实现页面缓存或动作缓存
下面是该线程的示例解决方案:https://github.com/activeadmin/activeadmin/issues/2263#issuecomment-20249617
# application_helper.rb
# Caches Arbre output.
#
# context - ActiveAdmin instance context
# args - Arguments passed to Rails.cache calls.
#
# Yielding the first time adds to the output buffer regardless of the
# returned value. The missed cache must be handled carefully.
#
# Returns yielded Arbre on cache miss OR an HTML string wrapped in
# an Arbre div on cache hit.
def cache_arbre(context, *args)
if controller.perform_caching
if Rails.cache.exist?(*args)
context.instance_eval do
div(Rails.cache.read(*args))
end
else
Rails.cache.write(*args, yield.to_s)
end
else
yield
end
end
# Example Usage would be like the following:
ActiveAdmin.register User do
show do
arbre_cache(self, user.cache_key) do
attributes_table do
row :name
row :email
row :expensive_calculation
end
end
end
end
信用的源代码去@CMaresh https://stackoverflow.com/users/302824/cmaresh
同意..这是我的建议。 ;) – 2014-10-30 21:54:42