discourse/app/serializers/application_serializer.rb

Failed to ignore revisions in .git-blame-ignore-revs.

39 lines
690 B
Ruby
Raw Normal View History

# frozen_string_literal: true
require 'distributed_cache'
2013-02-05 14:16:51 -05:00
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
2013-02-07 10:45:24 -05:00
end