Sha256: 748cc681f26a36af23a734f92f33431ce94b1289d8d4a688c392adffcfcd099a

Contents?: true

Size: 748 Bytes

Versions: 28

Compression:

Stored size: 748 Bytes

Contents

module Friendly
  class Cache
    class ByID < Cache
      def store(document)
        cache.set(cache_key(document.id), document)
      end
      alias_method :create, :store
      alias_method :update, :store

      def destroy(document)
        cache.delete(cache_key(document.id))
      end

      def first(query, &block)
        cache.get(cache_key(query.conditions[:id]), &block)
      end

      def all(query, &block)
        keys = query.conditions[:id].map { |k| cache_key(k) }
        cache.multiget(keys, &block).values
      end

      def satisfies?(query)
        query.conditions.keys == [:id]
      end

      protected
        def cache_key(id)
          [klass.name, version, id.to_guid].join("/")
        end
    end
  end
end

Version data entries

28 entries across 28 versions & 7 rubygems

Version Path
ihoka-friendly-0.8.0.pre lib/friendly/cache/by_id.rb
ihoka-friendly-0.7.1.2 lib/friendly/cache/by_id.rb
ihoka-friendly-0.7.1.1 lib/friendly/cache/by_id.rb
ihoka-friendly-0.7.1 lib/friendly/cache/by_id.rb
ihoka-friendly-0.7.0 lib/friendly/cache/by_id.rb
ihoka-friendly-0.6.3 lib/friendly/cache/by_id.rb
ihoka-friendly-0.6.2 lib/friendly/cache/by_id.rb
friendly-0.6.0 lib/friendly/cache/by_id.rb
honkster-friendly-0.5.3 lib/friendly/cache/by_id.rb
honkster-friendly-0.5.2 lib/friendly/cache/by_id.rb
honkster-friendly-0.5.1 lib/friendly/cache/by_id.rb
wayne-friendly-0.5.1 lib/friendly/cache/by_id.rb
wego-friendly-0.5.1 lib/friendly/cache/by_id.rb
arunthampi-friendly-0.5.1 lib/friendly/cache/by_id.rb
friendly_postgres-0.5.1 lib/friendly/cache/by_id.rb
friendly-0.5.1 lib/friendly/cache/by_id.rb
friendly-0.5.0 lib/friendly/cache/by_id.rb
friendly_postgres-0.4.5 lib/friendly/cache/by_id.rb
friendly-0.4.5 lib/friendly/cache/by_id.rb
friendly-0.4.4 lib/friendly/cache/by_id.rb