Class: Aws::SessionStore::DynamoDB::Configuration
- Inherits:
-
Object
- Object
- Aws::SessionStore::DynamoDB::Configuration
- Defined in:
- lib/aws/session_store/dynamo_db/configuration.rb
Overview
This class provides a Configuration object for all DynamoDB session store operations by pulling configuration options from Runtime, the ENV, a YAML file, and default settings, in that order.
Environment Variables
The Configuration object can load default values from your environment. All configuration
keys are supported except for :dynamo_db_client and :error_handler. The keys take the form
of AWS_DYNAMO_DB_SESSION_<KEY_NAME>. Example:
export AWS_DYNAMO_DB_SESSION_TABLE_NAME='Sessions'
export AWS_DYNAMO_DB_SESSION_TABLE_KEY='id'
Locking Strategy
By default, locking is disabled for session store access. To enable locking, set the
:enable_locking option to true. The locking strategy is pessimistic, meaning that only one
read can be made on a session at once. While the session is being read by the process with the
lock, other processes may try to obtain a lock on the same session but will be blocked.
See the initializer for how to configure the pessimistic locking strategy to your needs.
Handling Errors
There are two configurable options for error handling: :raise_errors and :error_handler.
If you would like to use the Default Error Handler, you can decide to set :raise_errors
to true or false depending on whether you want all errors, regardless of class, to be raised
up the stack and essentially throw a 500.
If you decide to use your own Error Handler, you must implement the BaseErrorHandler
class and pass it into the :error_handler option.
DynamoDB Specific Options
You may configure the table name and table hash key value of your session table with
the :table_name and :table_key options. You may also configure performance options for
your table with the :consistent_read, :read_capacity, :write_capacity. For more information
about these configurations see
CreateTable
method for Amazon DynamoDB.
Constant Summary collapse
- MEMBERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ table_name: 'sessions', table_key: 'session_id', secret_key: nil, consistent_read: true, read_capacity: 10, write_capacity: 5, raise_errors: false, error_handler: nil, max_age: nil, max_stale: nil, enable_locking: false, lock_expiry_time: 500, lock_retry_delay: 500, lock_max_wait_time: 1, serializer: :marshal, config_file: nil, dynamo_db_client: nil }.freeze
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Configuration
constructor
Provides configuration object that allows access to options defined during Runtime, in the ENV, in a YAML file, and by default.
-
#to_hash ⇒ Hash
The merged configuration hash.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Provides configuration object that allows access to options defined during Runtime, in the ENV, in a YAML file, and by default.
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 114 def initialize( = {}) opts = opts = .merge(opts) opts = (opts).merge(opts) MEMBERS.each_pair do |opt_name, default_value| opts[opt_name] = default_value unless opts.key?(opt_name) end opts = opts.merge(dynamo_db_client: default_dynamo_db_client(opts)) opts = opts.merge(error_handler: default_error_handler(opts)) unless opts[:error_handler] set_attributes(opts) end |
Instance Method Details
#to_hash ⇒ Hash
Returns The merged configuration hash.
132 133 134 135 136 |
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 132 def to_hash MEMBERS.each_with_object({}) do |(key, _), hash| hash[key] = send(key) end end |