Class: Parse::Middleware::Caching
- Inherits:
- Faraday::Middleware
- Object
- Faraday::Middleware
- Parse::Middleware::Caching
- Includes:
- Protocol
- Defined in:
- lib/parse/client/caching.rb
Overview
This is a caching middleware for Parse queries using Moneta. The caching middleware will cache all GET requests made to the Parse REST API as long as the API responds with a successful non-empty result payload.
Whenever an object is created or updated, the corresponding entry in the cache when fetching the particular record (using the specific non-Query based API) will be cleared.
Constant Summary collapse
- CACHEABLE_HTTP_CODES =
List of status codes that can be cached:
-
200 - 'OK'
-
203 - 'Non-Authoritative Information'
-
300 - 'Multiple Choices'
-
301 - 'Moved Permanently'
-
302 - 'Found'
-
404 - 'Not Found' - removed
-
410 - 'Gone' - removed
-
[200, 203, 300, 301, 302].freeze
- CACHE_CONTROL =
Cache control header
"Cache-Control"
- CONTENT_LENGTH_KEY =
Request env key for the content length
"content-length"
- CACHE_RESPONSE_HEADER =
Header in response that is sent if this is a cached result
"X-Cache-Response"
- CACHE_EXPIRES_DURATION =
Header in request to set caching information for the middleware.
"X-Parse-Stack-Cache-Expires"
Constants included from Protocol
Protocol::API_KEY, Protocol::APP_ID, Protocol::CONTENT_TYPE, Protocol::CONTENT_TYPE_FORMAT, Protocol::EMAIL, Protocol::INSTALLATION_ID, Protocol::MASTER_KEY, Protocol::PASSWORD, Protocol::REVOCABLE_SESSION, Protocol::SERVER_URL, Protocol::SESSION_TOKEN
Class Attribute Summary collapse
- .enabled ⇒ Boolean
Whether the caching middleware should be enabled.
- .logging ⇒ Boolean
Whether the logging should be enabled.
Instance Attribute Summary collapse
- #expires ⇒ Integer
The expiration time in seconds for this particular request.
- #store ⇒ Moneta::Transformer, Moneta::Expires
The internal moneta cache store instance.
Class Method Summary collapse
- .caching? ⇒ Boolean
Whether caching is enabled.
Instance Method Summary collapse
- #initialize(adapter, store, opts = {}) ⇒ Caching constructor
Creates a new caching middleware.
Constructor Details
#initialize(adapter, store, opts = {}) ⇒ Caching
Creates a new caching middleware.
76 77 78 79 80 81 82 83 84 85 86 | # File 'lib/parse/client/caching.rb', line 76 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 |
Class Attribute Details
.enabled ⇒ Boolean
Returns whether the caching middleware should be enabled.
42 43 44 | # File 'lib/parse/client/caching.rb', line 42 def enabled @enabled end |
.logging ⇒ Boolean
Returns whether the logging should be enabled.
46 47 48 | # File 'lib/parse/client/caching.rb', line 46 def logging @logging end |
Instance Attribute Details
#expires ⇒ Integer
The expiration time in seconds for this particular request.
67 68 69 | # File 'lib/parse/client/caching.rb', line 67 def expires @expires end |
#store ⇒ Moneta::Transformer, Moneta::Expires
The internal moneta cache store instance.
62 63 64 | # File 'lib/parse/client/caching.rb', line 62 def store @store end |
Class Method Details
.caching? ⇒ Boolean
Returns whether caching is enabled.
54 55 56 | # File 'lib/parse/client/caching.rb', line 54 def caching? @enabled end |