module FastSerializer
Public Class Methods
cache()
click to toggle source
Get the global cache implementation used for storing cacheable serializers.
# File lib/fast_serializer.rb, line 19 def cache @cache end
cache=(cache)
click to toggle source
Set the global cache implementation used for storing cacheable serializers. The cache implementation should implement the fetch
method as defined in FastSerializer::Cache
. By default no cache is set so caching won't do anything.
In a Rails app, you can initialize the cache by simply passing in the value :rails to use the default Rails.cache. You can also directly pass in an ActiveSupportCache::Store.
# File lib/fast_serializer.rb, line 29 def cache=(cache) if cache == :rails cache = Cache::ActiveSupportCache.new(Rails.cache) elsif defined?(ActiveSupport::Cache::Store) && cache.is_a?(ActiveSupport::Cache::Store) cache = Cache::ActiveSupportCache.new(cache) end if cache && !cache.is_a?(FastSerializer::Cache) raise ArgumentError.new("The cache must be a FastSerializer::Cache or ActiveSupport::Cache::Store") end @cache = cache end