Module: Stockpile
- Defined in:
- lib/stockpile.rb,
lib/stockpile/lock.rb,
lib/stockpile/cache.rb,
lib/stockpile/executor.rb,
lib/stockpile/constants.rb,
lib/stockpile/configuration.rb,
lib/stockpile/redis_connection.rb,
lib/stockpile/cached_value_reader.rb,
lib/stockpile/failed_lock_execution.rb,
lib/stockpile/locked_execution_result.rb
Overview
Copyright 2019 ConvertKit, LLC
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defined Under Namespace
Modules: Cache, CachedValueReader, RedisConnection Classes: Configuration, Executor, FailedLockExecution, Lock, LockedExcutionResult
Constant Summary collapse
- DEFAULT_CONNECTION_POOL =
100- DEFAULT_CONNECTION_TIMEOUT =
3- DEFAULT_LOCK_EXPIRATION =
10- DEFAULT_REDIS_URL =
'redis://localhost:6379/1'- DEFAULT_SLUMBER =
2- DEFAULT_TTL =
60 * 5
- LOCK_PREFIX =
'stockpile_lock::'- SLUMBER_COOLDOWN =
0.05
- VERSION =
'1.0.0'
Class Method Summary collapse
-
.configuration ⇒ Configuration
Provides access to cache’s configuration.
-
.configure {|configuration| ... } ⇒ void
API to configure cache dynamically during runtime.
-
.perform_cached(key:, ttl: Stockpile::DEFAULT_TTL) {|block| ... } ⇒ Object
Attempts to fetch a value from cache (for a given key).
-
.redis {|redis| ... } ⇒ Object
API to communicate with Redis database backing cache up.
-
.redis_connection_pool ⇒ ConnectionPool
Accessor to connection pool.
Class Method Details
.configuration ⇒ Configuration
Provides access to cache’s configuration.
57 58 59 |
# File 'lib/stockpile.rb', line 57 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ void
This method returns an undefined value.
API to configure cache dynamically during runtime.
70 71 72 73 |
# File 'lib/stockpile.rb', line 70 def configure yield(configuration) nil end |
.perform_cached(key:, ttl: Stockpile::DEFAULT_TTL) {|block| ... } ⇒ Object
Attempts to fetch a value from cache (for a given key). In case of miss will execute given block of code and cache it’s result at the provided key for a specified TTL.
90 91 92 |
# File 'lib/stockpile.rb', line 90 def perform_cached(key:, ttl: Stockpile::DEFAULT_TTL, &block) Stockpile::CachedValueReader.read_or_yield(key: key, ttl: ttl, &block) end |
.redis {|redis| ... } ⇒ Object
API to communicate with Redis database backing cache up.
102 103 104 105 106 |
# File 'lib/stockpile.rb', line 102 def redis redis_connection_pool.with do |connection| yield connection end end |
.redis_connection_pool ⇒ ConnectionPool
Accessor to connection pool. Defined on top level so it can be memoized on the topmost level
112 113 114 |
# File 'lib/stockpile.rb', line 112 def redis_connection_pool @redis_connection_pool ||= Stockpile::RedisConnection.connection_pool end |