2015-09-28 01:40:27 -05:00
|
|
|
require 'distributed_cache'
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
class ApplicationSerializer < ActiveModel::Serializer
|
2013-03-23 10:02:59 -05:00
|
|
|
embed :ids, include: true
|
2015-09-28 01:40:27 -05:00
|
|
|
|
|
|
|
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 09:45:24 -06:00
|
|
|
end
|