我们在我们的应用程序中使用活动管理员。我有大量数据等需要管理。我想在活动管理员中实现页面缓存/动作缓存,并希望在我的特定调用中使片段过期。我不介意在索引页面上显示一段时间的陈旧数据。有人可以提供一些基本示例如何在活动管理员中实现 page_caching/action_caching 吗?
问问题
1388 次
1 回答
3
这是来自该线程的示例解决方案: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-20T22:22:36.313 回答