summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/Memcached_DataObject.php83
-rw-r--r--classes/statusnet.ini2
-rw-r--r--plugins/CasAuthentication/CasAuthenticationPlugin.php9
-rw-r--r--plugins/CasAuthentication/README6
-rw-r--r--plugins/MemcachePlugin.php18
5 files changed, 78 insertions, 40 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index 1608720d1..020d813b2 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -152,52 +152,69 @@ class Memcached_DataObject extends DB_DataObject
function encache()
{
$c = $this->memcache();
+
if (!$c) {
return false;
- } else {
- $pkey = array();
- $pval = array();
- $types = $this->keyTypes();
- ksort($types);
- foreach ($types as $key => $type) {
- if ($type == 'K') {
- $pkey[] = $key;
- $pval[] = $this->$key;
- } else {
- $c->set($this->cacheKey($this->tableName(), $key, $this->$key), $this);
- }
- }
- # XXX: should work for both compound and scalar pkeys
- $pvals = implode(',', $pval);
- $pkeys = implode(',', $pkey);
- $c->set($this->cacheKey($this->tableName(), $pkeys, $pvals), $this);
+ }
+
+ $keys = $this->_allCacheKeys();
+
+ foreach ($keys as $key) {
+ $c->set($key, $this);
}
}
function decache()
{
$c = $this->memcache();
+
if (!$c) {
return false;
- } else {
- $pkey = array();
- $pval = array();
- $types = $this->keyTypes();
- ksort($types);
- foreach ($types as $key => $type) {
- if ($type == 'K') {
- $pkey[] = $key;
- $pval[] = $this->$key;
- } else {
- $c->delete($this->cacheKey($this->tableName(), $key, $this->$key));
+ }
+
+ $keys = $this->_allCacheKeys();
+
+ foreach ($keys as $key) {
+ $c->delete($key, $this);
+ }
+ }
+
+ function _allCacheKeys()
+ {
+ $ckeys = array();
+
+ $types = $this->keyTypes();
+ ksort($types);
+
+ $pkey = array();
+ $pval = array();
+
+ foreach ($types as $key => $type) {
+
+ assert(!empty($key));
+
+ if ($type == 'U') {
+ if (empty($this->$key)) {
+ continue;
}
+ $ckeys[] = $this->cacheKey($this->tableName(), $key, $this->$key);
+ } else if ($type == 'K' || $type == 'N') {
+ $pkey[] = $key;
+ $pval[] = $this->$key;
+ } else {
+ throw new Exception("Unknown key type $key => $type for " . $this->tableName());
}
- # should work for both compound and scalar pkeys
- # XXX: comma works for now but may not be safe separator for future keys
- $pvals = implode(',', $pval);
- $pkeys = implode(',', $pkey);
- $c->delete($this->cacheKey($this->tableName(), $pkeys, $pvals));
}
+
+ assert(count($pkey) > 0);
+
+ // XXX: should work for both compound and scalar pkeys
+ $pvals = implode(',', $pval);
+ $pkeys = implode(',', $pkey);
+
+ $ckeys[] = $this->cacheKey($this->tableName(), $pkeys, $pvals);
+
+ return $ckeys;
}
function multicache($cls, $kv)
diff --git a/classes/statusnet.ini b/classes/statusnet.ini
index 4077746c4..ac31148da 100644
--- a/classes/statusnet.ini
+++ b/classes/statusnet.ini
@@ -572,5 +572,5 @@ created = 142
modified = 384
[user_location_prefs__keys]
-user_id = U
+user_id = K
diff --git a/plugins/CasAuthentication/CasAuthenticationPlugin.php b/plugins/CasAuthentication/CasAuthenticationPlugin.php
index 8b6ef5462..8f29c7d2a 100644
--- a/plugins/CasAuthentication/CasAuthenticationPlugin.php
+++ b/plugins/CasAuthentication/CasAuthenticationPlugin.php
@@ -40,6 +40,7 @@ class CasAuthenticationPlugin extends AuthenticationPlugin
public $server;
public $port = 443;
public $path = '';
+ public $takeOverLogin = false;
function checkPassword($username, $password)
{
@@ -62,6 +63,14 @@ class CasAuthenticationPlugin extends AuthenticationPlugin
}
}
+ function onArgsInitialize(&$args)
+ {
+ if($this->takeOverLogin && $args['action'] == 'login')
+ {
+ $args['action'] = 'caslogin';
+ }
+ }
+
function onStartInitializeRouter($m)
{
$m->connect('main/cas', array('action' => 'caslogin'));
diff --git a/plugins/CasAuthentication/README b/plugins/CasAuthentication/README
index 2ee54dc05..c17a28e54 100644
--- a/plugins/CasAuthentication/README
+++ b/plugins/CasAuthentication/README
@@ -21,6 +21,9 @@ password_changeable*: must be set to false. This plugin does not support changin
server*: CAS server to authentication against
port (443): Port the CAS server listens on. Almost always 443
path (): Path on the server to CAS. Usually blank.
+takeOverLogin (false): Take over the main login action. If takeOverLogin is
+ set, anytime the standard username/password login form would be shown,
+ a CAS login will be done instead.
* required
default values are in (parenthesis)
@@ -33,6 +36,7 @@ addPlugin('casAuthentication', array(
'autoregistration'=>true,
'server'=>'sso-cas.univ-rennes1.fr',
'port'=>443,
- 'path'=>''
+ 'path'=>'',
+ 'takeOverLogin'=>true
));
diff --git a/plugins/MemcachePlugin.php b/plugins/MemcachePlugin.php
index 78e2b2406..998766313 100644
--- a/plugins/MemcachePlugin.php
+++ b/plugins/MemcachePlugin.php
@@ -54,6 +54,9 @@ class MemcachePlugin extends Plugin
private $_conn = null;
public $servers = array('127.0.0.1;11211');
+ public $compressThreshold = 20480;
+ public $compressMinSaving = 0.2;
+
/**
* Initialize the plugin
*
@@ -156,11 +159,16 @@ class MemcachePlugin extends Plugin
}
$this->_conn->addServer($host, $port);
}
- //Compress items stored in the cache if they're over 2k in size
- //and the compression would save more than 20%.
- //Allows the cache to store objects larger than 1MB (if they
- //compress to less than 1MB), and improves cache memory efficiency.
- $this->_conn->setCompressThreshold(20000, 0.2);
+
+ // Compress items stored in the cache if they're over threshold in size
+ // (default 2KiB) and the compression would save more than min savings
+ // ratio (default 0.2).
+
+ // Allows the cache to store objects larger than 1MB (if they
+ // compress to less than 1MB), and improves cache memory efficiency.
+
+ $this->_conn->setCompressThreshold($this->compressThreshold,
+ $this->compressMinSaving);
}
}
}