mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 18:43:38 +08:00
f8b70f4ca3
Previous attempt at 70adb940
missed the critical "everyone" group from
staff, leading to a case where staff was no longer able to create categories
37 lines
659 B
Ruby
37 lines
659 B
Ruby
require 'distributed_cache'
|
|
|
|
class ApplicationSerializer < ActiveModel::Serializer
|
|
embed :ids, include: true
|
|
|
|
class CachedFragment
|
|
def initialize(json)
|
|
@json = json
|
|
end
|
|
def as_json(*_args)
|
|
@json
|
|
end
|
|
end
|
|
|
|
def self.expire_cache_fragment!(name)
|
|
fragment_cache.delete(name)
|
|
end
|
|
|
|
def self.fragment_cache
|
|
@cache ||= DistributedCache.new("am_serializer_fragment_cache")
|
|
end
|
|
|
|
protected
|
|
|
|
def cache_fragment(name)
|
|
ApplicationSerializer.fragment_cache[name] ||= yield
|
|
end
|
|
|
|
def cache_anon_fragment(name, &blk)
|
|
if scope.anonymous?
|
|
cache_fragment(name, &blk)
|
|
else
|
|
blk.call
|
|
end
|
|
end
|
|
end
|