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_connections.rb,
lib/stockpile/cached_value_reader.rb,
lib/stockpile/cached_value_expirer.rb,
lib/stockpile/failed_lock_execution.rb,
lib/stockpile/locked_execution_result.rb,
lib/stockpile/yaml_redis_configuration.rb,
lib/stockpile/redis_connections_factory.rb,
lib/stockpile/default_redis_configuration.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, CachedValueExpirer, CachedValueReader, DefaultRedisConfiguration, RedisConnections, RedisConnectionsFactory, YamlRedisConfiguration 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.4.0'
Class Method Summary collapse
-
.configuration ⇒ Configuration
Provides access to cache’s configuration.
-
.configure {|configuration| ... } ⇒ void
API to configure cache dynamically during runtime.
-
.expire_cached(db: :default, key:) ⇒ true, false
Immediatelly expires a cached value for a given key.
-
.perform_cached(db: :default, key:, ttl: Stockpile::DEFAULT_TTL) {|block| ... } ⇒ Object
Attempts to fetch a value from cache (for a given key).
-
.redis(db: :default) {|redis| ... } ⇒ Object
API to communicate with Redis database backing cache up.
-
.redis_connections ⇒ Stockpile::RedisConnections
Accessor to connection pool.
Class Method Details
.configuration ⇒ Configuration
Provides access to cache’s configuration.
65 66 67 |
# File 'lib/stockpile.rb', line 65 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ void
This method returns an undefined value.
API to configure cache dynamically during runtime. Running dynamic configuration will rebuild connection pools releasing existing connections.
80 81 82 83 84 85 |
# File 'lib/stockpile.rb', line 80 def configure yield(configuration) @redis_connections = Stockpile::RedisConnectionsFactory.build_connections nil end |
.expire_cached(db: :default, key:) ⇒ true, false
Immediatelly expires a cached value for a given key.
95 96 97 |
# File 'lib/stockpile.rb', line 95 def expire_cached(db: :default, key:) Stockpile::CachedValueExpirer.expire_cached(db: db, key: key) end |
.perform_cached(db: :default, 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.
116 117 118 119 120 121 122 123 |
# File 'lib/stockpile.rb', line 116 def perform_cached(db: :default, key:, ttl: Stockpile::DEFAULT_TTL, &block) Stockpile::CachedValueReader.read_or_yield( db: db, key: key, ttl: ttl, &block ) end |
.redis(db: :default) {|redis| ... } ⇒ Object
API to communicate with Redis database backing cache up.
133 134 135 136 137 |
# File 'lib/stockpile.rb', line 133 def redis(db: :default) redis_connections.with(db: db) do |connection| yield connection end end |
.redis_connections ⇒ Stockpile::RedisConnections
Accessor to connection pool. Defined on top level so it can be memoized on the topmost level
144 145 146 |
# File 'lib/stockpile.rb', line 144 def redis_connections @redis_connections ||= Stockpile::RedisConnectionsFactory.build_connections end |