oj_serializers icon indicating copy to clipboard operation
oj_serializers copied to clipboard

add configuration and cache options

Open Stanislav-Lapata opened this issue 9 months ago • 0 comments

This PR adds configuration

OjSerializers.configure do |config|
  config.cache = SomeCacheModule.new
end

and adds cache_options

class SomeSerializer < Oj::Serializer
  attributes :id, :name
end

class CachedSomeSerializer < SomeSerializer
  cached(cache_key: ->(object) { object.id }, options: { expires_id: 1.minute, ... }) # args are optional 
  # or
  cached_with_key ->(object) { object.id }
  # or
  cached_with_options expires_in: 1.minute
end

PR also has breaking changes

Stanislav-Lapata avatar Sep 12 '23 08:09 Stanislav-Lapata