Class: GraphQL::PersistedQueries::StoreAdapters::MemcachedStoreAdapter

Inherits:
BaseStoreAdapter
  • Object
show all
Defined in:
lib/graphql/persisted_queries/store_adapters/memcached_store_adapter.rb

Overview

Redis adapter for storing persisted queries

Constant Summary collapse

DEFAULT_EXPIRATION =
24 * 60 * 60
DEFAULT_NAMESPACE =
"graphql-persisted-query"

Instance Attribute Summary

Attributes inherited from BaseStoreAdapter

#tracers

Instance Method Summary collapse

Methods inherited from BaseStoreAdapter

#fetch_query, #save_query, #trace

Constructor Details

#initialize(dalli_client:, expiration: nil, namespace: nil) ⇒ MemcachedStoreAdapter

Returns a new instance of MemcachedStoreAdapter.



13
14
15
16
17
18
# File 'lib/graphql/persisted_queries/store_adapters/memcached_store_adapter.rb', line 13

def initialize(dalli_client:, expiration: nil, namespace: nil)
  @dalli_proc = build_dalli_proc(dalli_client)
  @expiration = expiration || DEFAULT_EXPIRATION
  @namespace = namespace || DEFAULT_NAMESPACE
  @name = :memcached
end

Instance Method Details

#fetch(hash) ⇒ Object



20
21
22
# File 'lib/graphql/persisted_queries/store_adapters/memcached_store_adapter.rb', line 20

def fetch(hash)
  @dalli_proc.call { |dalli| dalli.get(key_for(hash)) }
end

#save(hash, query) ⇒ Object



24
25
26
# File 'lib/graphql/persisted_queries/store_adapters/memcached_store_adapter.rb', line 24

def save(hash, query)
  @dalli_proc.call { |dalli| dalli.set(key_for(hash), query, @expiration) }
end