Sha256: 1f1539c320e614511269c3cafdbe264f0b8c263a2949f94050700bf45c04b739

Contents?: true

Size: 658 Bytes

Versions: 3

Compression:

Stored size: 658 Bytes

Contents

# frozen_string_literal: true
module ActiveModelSerializers
  class Model
    module Caching
      extend ActiveSupport::Concern

      included do
        attr_writer :updated_at
        attributes :id
      end

      # Defaults to the downcased model name and updated_at
      def cache_key
        ActiveSupport::Cache.expand_cache_key([
          self.class.model_name.name.downcase,
          "#{id}-#{updated_at.strftime('%Y%m%d%H%M%S%9N')}"
        ].compact)
      end

      # Defaults to the time the serializer file was modified.
      def updated_at
        defined?(@updated_at) ? @updated_at : File.mtime(__FILE__)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_model_serializers-0.10.14 lib/active_model_serializers/model/caching.rb
active_model_serializers-0.9.9 lib/active_model_serializers/model/caching.rb
active_model_serializers-0.10.13 lib/active_model_serializers/model/caching.rb