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