mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Extract caching of homepage stats to service
This commit is contained in:
@@ -18,9 +18,11 @@ class HomeController < BaseController
|
||||
|
||||
private
|
||||
|
||||
# Cache the value of the query count for 24 hours
|
||||
# Cache the value of the query count
|
||||
def cached_count(key, query)
|
||||
Rails.cache.fetch("home_stats_count_#{key}", expires_in: 1.day, race_condition_ttl: 10) do
|
||||
CacheService.cache("home_stats_count_#{key}",
|
||||
expires_in: CacheService::HOME_STATS_EXPIRY,
|
||||
race_condition_ttl: 10) do
|
||||
query.count
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CacheService
|
||||
HOME_STATS_EXPIRY = 1.day.freeze
|
||||
FILTERS_EXPIRY = 30.seconds.freeze
|
||||
|
||||
def self.cache(cache_key, options = {})
|
||||
|
||||
Reference in New Issue
Block a user