mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-11 00:02:05 -05:00
28 lines
525 B
Ruby
28 lines
525 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
|
|
end
|