Class: GraphQL::PersistedQueries::StoreAdapters::RedisWithLocalCacheStoreAdapter
- Inherits:
-
BaseStoreAdapter
- Object
- BaseStoreAdapter
- GraphQL::PersistedQueries::StoreAdapters::RedisWithLocalCacheStoreAdapter
- Defined in:
- lib/graphql/persisted_queries/store_adapters/redis_with_local_cache_store_adapter.rb
Overview
Memory adapter for storing persisted queries
Constant Summary collapse
- DEFAULT_REDIS_ADAPTER_CLASS =
RedisStoreAdapter- DEFAULT_MEMORY_ADAPTER_CLASS =
MemoryStoreAdapter
Instance Attribute Summary
Attributes inherited from BaseStoreAdapter
Instance Method Summary collapse
-
#fetch(hash) ⇒ Object
rubocop:enable Metrics/ParameterLists, Metrics/MethodLength.
-
#initialize(redis_client: {}, expiration: nil, namespace: nil, redis_adapter_class: nil, memory_adapter_class: nil, marshal_inmemory_queries: true) ⇒ RedisWithLocalCacheStoreAdapter
constructor
rubocop:disable Metrics/ParameterLists, Metrics/MethodLength.
- #save(hash, query) ⇒ Object
Methods inherited from BaseStoreAdapter
#deserialize, #fetch_query, #save_query, #serialize, #trace
Constructor Details
#initialize(redis_client: {}, expiration: nil, namespace: nil, redis_adapter_class: nil, memory_adapter_class: nil, marshal_inmemory_queries: true) ⇒ RedisWithLocalCacheStoreAdapter
rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/graphql/persisted_queries/store_adapters/redis_with_local_cache_store_adapter.rb', line 12 def initialize(redis_client: {}, expiration: nil, namespace: nil, redis_adapter_class: nil, memory_adapter_class: nil, marshal_inmemory_queries: true) redis_adapter_class ||= DEFAULT_REDIS_ADAPTER_CLASS memory_adapter_class ||= DEFAULT_MEMORY_ADAPTER_CLASS @redis_adapter = redis_adapter_class.new( redis_client: redis_client, expiration: expiration, namespace: namespace ) @marshal_inmemory_queries = marshal_inmemory_queries @memory_adapter = memory_adapter_class.new( marshal_inmemory_queries: marshal_inmemory_queries ) @name = :redis_with_local_cache end |
Instance Method Details
#fetch(hash) ⇒ Object
rubocop:enable Metrics/ParameterLists, Metrics/MethodLength
30 31 32 33 34 35 36 37 38 |
# File 'lib/graphql/persisted_queries/store_adapters/redis_with_local_cache_store_adapter.rb', line 30 def fetch(hash) result = @memory_adapter.fetch(hash) result ||= begin inner_result = @redis_adapter.fetch(hash) @memory_adapter.save(hash, inner_result) if inner_result inner_result end result end |
#save(hash, query) ⇒ Object
40 41 42 43 |
# File 'lib/graphql/persisted_queries/store_adapters/redis_with_local_cache_store_adapter.rb', line 40 def save(hash, query) @redis_adapter.save(hash, query) @memory_adapter.save(hash, query) end |