Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/199825
Change subject: Introduced User::touch() method to bump the getTouched() value
using memcached
......................................................................
Introduced User::touch() method to bump the getTouched() value using memcached
* This lets some callers avoid the heavyweight invalidateCache() method
Bug: T92357
Change-Id: I8c1c7ff9c5574f0eca23e7effde199ab13a19231
---
M includes/User.php
1 file changed, 49 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/25/199825/1
diff --git a/includes/User.php b/includes/User.php
index 97eaa5c..6e45fa5 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -204,8 +204,10 @@
public $mNewpassTime;
public $mEmail;
-
+ /** @var stirng TS_MW timestamp from DB */
public $mTouched;
+ /** @var string TS_MW timestamp from cache */
+ protected $mQuickTouched;
protected $mToken;
@@ -429,6 +431,8 @@
* Save user data to the shared cache
*/
public function saveToCache() {
+ global $wgMemc;
+
$this->load();
$this->loadGroups();
$this->loadOptions();
@@ -442,7 +446,7 @@
}
$data['mVersion'] = self::VERSION;
$key = wfMemcKey( 'user', 'id', $this->mId );
- global $wgMemc;
+
$wgMemc->set( $key, $data );
}
@@ -2214,9 +2218,10 @@
* Called implicitly from invalidateCache() and saveSettings().
*/
public function clearSharedCache() {
+ global $wgMemc;
+
$this->load();
if ( $this->mId ) {
- global $wgMemc;
$wgMemc->delete( wfMemcKey( 'user', 'id', $this->mId )
);
}
}
@@ -2256,6 +2261,31 @@
}
/**
+ * Update the "touched" timestamp for the user
+ *
+ * This is useful on various login/logout events when making sure that
+ * a browser or proxy that has multiple tenants does not suffer cache
+ * pollution where the new user sees the old users content. The value
+ * of getTouched() is checked when determining 304 vs 200 responses.
+ * Unlike invalidateCache(), this preserves the User object cache and
+ * avoids database writes.
+ *
+ * @since 1.25
+ */
+ public function touch() {
+ global $wgMemc;
+
+ $this->load();
+
+ if ( $this->mId ) {
+ $key = wfMemcKey( 'user-quicktouched', 'id', $this->mId
);
+ $timestamp = self::newTouchedTimestamp();
+ $wgMemc->set( $key, $timestamp );
+ $this->mQuickTouched = $timestamp;
+ }
+ }
+
+ /**
* Validate the cache for this account.
* @param string $timestamp A timestamp in TS_MW format
* @return bool
@@ -2267,10 +2297,25 @@
/**
* Get the user touched timestamp
- * @return string Timestamp
+ * @return string TS_MW Timestamp
*/
public function getTouched() {
+ global $wgMemc;
+
$this->load();
+
+ if ( $this->mId ) {
+ if ( $this->mQuickTouched === null ) {
+ $key = wfMemcKey( 'user-quicktouched', 'id',
$this->mId );
+ $timestamp = $wgMemc->get( $key );
+ if ( !$timestamp ) {
+ $this->touch();
+ }
+ }
+
+ return max( $this->mTouched, $this->mQuickTouched );
+ }
+
return $this->mTouched;
}
--
To view, visit https://gerrit.wikimedia.org/r/199825
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8c1c7ff9c5574f0eca23e7effde199ab13a19231
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits