discourse/app/serializers/application_serializer.rb

29 lines
525 B
Ruby
Raw Normal View History

require 'distributed_cache'
2013-02-06 03:16:51 +08: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
2013-02-07 23:45:24 +08:00
end