Module: Aws::SessionStore::DynamoDB::GarbageCollection

Defined in:
lib/aws/session_store/dynamo_db/garbage_collection.rb

Overview

Collects and deletes unwanted sessions based on their creation and update dates.

Class Method Summary collapse

Class Method Details

.collect_garbage(options = {}) ⇒ Object

Scans DynamoDB session table to find sessions that match the max age and max stale period requirements. it then deletes all of the found sessions.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :table_name (String) — default: "sessions"

    Name of the session table.

  • :table_key (String) — default: "session_id"

    The hash key of the session table.

  • :secret_key (String)

    Secret key for HMAC encryption.

  • :consistent_read (Boolean) — default: true

    If true, a strongly consistent read is used. If false, an eventually consistent read is used. @see docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html

  • :read_capacity (Integer) — default: 10

    The maximum number of strongly consistent reads consumed per second before DynamoDB raises a ThrottlingException. @see docs.aws.amazon.com/amazondynamodb/latest/developerguide/read-write-operations.html

  • :write_capacity (Integer) — default: 5

    The maximum number of writes consumed per second before DynamoDB returns a ThrottlingException. @see docs.aws.amazon.com/amazondynamodb/latest/developerguide/read-write-operations.html

  • :raise_errors (Boolean) — default: false

    If true, all errors are raised up the stack when default ErrorHandler. If false, Only specified errors are raised up the stack when the default ErrorHandler is used.

  • :error_handler (#handle_error) — default: Errors::DefaultHandler

    An error handling object that handles all exceptions thrown during execution of the rack application.

  • :max_age (Integer) — default: nil

    Maximum number of seconds earlier from the current time that a session was created.

  • :max_stale (Integer) — default: nil

    Maximum number of seconds before current time that session was last accessed.

  • :enable_locking (Integer) — default: false

    If true, a pessimistic locking strategy will be used for all session accesses.

  • :lock_expiry_time (Integer) — default: 500

    Time in milliseconds after which the lock expires on session.

  • :lock_retry_delay (Integer) — default: 500

    Time in milliseconds to wait before retrying to obtain lock once an attempt to obtain the lock has been made and has failed.

  • :lock_max_wait_time (Integer) — default: 500

    Maximum time in seconds to wait to acquire the lock before giving up.

  • :config_file (String, Pathname)

    Path to a YAML file that contains configuration options.

  • :dynamo_db_client (Aws::DynamoDB::Client) — default: Aws::DynamoDB::Client.new

    DynamoDB client used to perform database operations inside of the rack application.



13
14
15
16
17
# File 'lib/aws/session_store/dynamo_db/garbage_collection.rb', line 13

def collect_garbage(options = {})
  config = load_config(options)
  last_key = eliminate_unwanted_sessions(config)
  last_key = eliminate_unwanted_sessions(config, last_key) until last_key.empty?
end