Method: Parse::Middleware::Caching#initialize

Defined in:
lib/parse/client/caching.rb

#initialize(adapter, store, opts = {}) ⇒ Caching

Creates a new caching middleware.

Parameters:

  • adapter (Faraday::Adapter)

    An instance of the Faraday adapter used for the connection. Defaults Faraday::Adapter::NetHttp.

  • store (Moneta)

    An instance of the Moneta cache store to use.

  • opts (Hash) (defaults to: {})

    additional options.

Options Hash (opts):

  • :expires (Integer)

    the default expiration for a cache entry.

Raises:

  • ArgumentError, if store is not a Moneta::Transformer or Moneta::Expires instance.



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/parse/client/caching.rb', line 77

def initialize(adapter, store, opts = {})
  super(adapter)
  @store = store
  @opts = {expires: 0}
  @opts.merge!(opts) if opts.is_a?(Hash)
  @expires = @opts[:expires]

  unless [:key?, :[], :delete, :store].all? { |method| @store.respond_to?(method) }
    raise ArgumentError, "Caching store object must a Moneta key/value store."
  end

end