Skip to content

Commit

Permalink
Merge pull request #14 from dhensby/pulls/fix-session-lifetime
Browse files Browse the repository at this point in the history
FIX AWS_DYNAMODB_SESSION_LIFETIME has no effect
  • Loading branch information
Stig Lindqvist committed Mar 3, 2016
2 parents 11a9d52 + 7f10513 commit 2d1eefe
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions code/model/DynamoDbSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,41 @@ public static function get()
$dynamoOptions['credentials.cache'] = true;
}

if (defined('AWS_DYNAMODB_SESSION_LIFETIME')) {
$dynamoOptions['session_lifetime'] = AWS_DYNAMODB_SESSION_LIFETIME;
}

return new DynamoDbSession($dynamoOptions, AWS_DYNAMODB_SESSION_TABLE);
return new static($dynamoOptions, AWS_DYNAMODB_SESSION_TABLE);
}

return null;
}

public function __construct($options, $table)
{
// refer to the Session class to find the session timeout value (if it exists)
// in terms of DynamoDB, session_lifetime is the time to mark the inactive
// session to be garbage collected
// if {@link GarbageCollectSessionCronTask} is running periodically on your
// server (via the silverstripe-crontask module), then the inactive session
// will get removed from the DynamoDB session table.
if (!isset($options['session_lifetime'])) {
$timeout = Config::inst()->get('Session', 'timeout');
if ($timeout != null) {
$options['session_lifetime'] = $timeout;
}
}

$this->client = DynamoDbClient::factory($options);
$this->table = $table;
$this->handler = SessionHandler::factory(array(
'dynamodb_client' => $this->client,
'table_name' => $this->table,
'session_lifetime' => $this->getSessionLifetime(),
));
}

/**
* check the AWS constant or refer to the Session class to find the session timeout value (if it exists) in terms
* of DynamoDB, session_lifetime is the time to mark the inactive session to be garbage collected
* if {@link GarbageCollectSessionCronTask} is running periodically on your server (via the silverstripe-crontask
* module), then the inactive session will get removed from the DynamoDB session table.
*
* @return int The session lifetime
*/
protected function getSessionLifetime() {
if (defined('AWS_DYNAMODB_SESSION_LIFETIME')) {
return AWS_DYNAMODB_SESSION_LIFETIME;
}
if (($timeout = (int)Config::inst()->get('Session', 'timeout')) > 0) {
return $timeout;
}
return (int) ini_get('session.gc_maxlifetime');
}

/**
* Register DynamoDB as the session handler.
*/
Expand Down

0 comments on commit 2d1eefe

Please sign in to comment.