Skip to content
Snippets Groups Projects
Commit 285bc961 authored by Olav Morken's avatar Olav Morken
Browse files

Added option to set the expiry time of data in the memcache servers.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@83 44740490-163a-0410-bde0-09ae8108e29a
parent 61fa7c48
No related branches found
No related tags found
No related merge requests found
...@@ -153,6 +153,23 @@ $config = array ( ...@@ -153,6 +153,23 @@ $config = array (
), ),
/*
* This value is the duration data should be stored in memcache. Data
* will be dropped from the memcache servers when this time expires.
* The time will be reset every time the data is written to the
* memcache servers.
*
* This value should always be larger than the 'session.duration'
* option. Not doing this may result in the session being deleted from
* the memcache servers while it is still in use.
*
* Set this value to 0 if you don't want data to expire.
*
* Note: The oldest data will always be deleted if the memcache server
* runs out of storage space.
*/
'memcache_store.expires' => 36 * (60*60), // 36 hours.
); );
......
...@@ -281,7 +281,8 @@ class SimpleSAML_MemcacheStore { ...@@ -281,7 +281,8 @@ class SimpleSAML_MemcacheStore {
/* Store this object to all groups of memcache servers. */ /* Store this object to all groups of memcache servers. */
foreach(self::getMemcacheServers() as $server) { foreach(self::getMemcacheServers() as $server) {
$server->set($this->id, $this->savedData); $server->set($this->id, $this->savedData, 0,
self::getExpireTime());
} }
} }
...@@ -565,5 +566,66 @@ class SimpleSAML_MemcacheStore { ...@@ -565,5 +566,66 @@ class SimpleSAML_MemcacheStore {
return TRUE; return TRUE;
} }
/* This is a helper-function which returns the expire value of data
* we should store to the memcache servers.
*
* The value is set depending on the configuration. If no value is
* set in the configuration, then we will use a default value of 0.
* 0 means that the item will never expire.
*
* Returns:
* The value which should be passed in the set(...) calls to the
* memcache objects.
*/
private static function getExpireTime()
{
/* Get the configuration instance. */
$config = SimpleSAML_Configuration::getInstance();
assert($config instanceof SimpleSAML_Configuration);
/* Get the expire-value from the configuration. */
$expire = $config->getValue('memcache_store.expires');
/* If 'memcache_store.expires' isn't defined in the
* configuration, then we will use 0 as the expire parameter.
*/
if($expire === NULL) {
return 0;
}
/* The 'memcache_store.expires' option must be an integer. */
if(!is_integer($expire)) {
$e = 'The value of \'memcache_store.expires\' in the' .
' configuration must be a valid integer.';
error_log($e);
die($e);
}
/* It must be a positive integer. */
if($expire < 0) {
$e = 'The value of \'memcache_store.expires\' in the' .
' configuration can\'t be a negative integer.';
error_log($e);
die($e);
}
/* If the configuration option is 0, then we should
* return 0. This allows the user to specify that the data
* shouldn't expire.
*/
if($expire == 0) {
return 0;
}
/* The expire option is given as the number of seconds into the
* future an item should expire. We convert this to an actual
* timestamp.
*/
$expireTime = time() + $expire;
return $expireTime;
}
} }
?> ?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment