Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/250297

Change subject: Make HashBagOStuff's internal data array simpler
......................................................................

Make HashBagOStuff's internal data array simpler

One of the nice things about HashBagOStuff is that it can be used as a simple
wrapper around an array. Icca2474b1ea6f throws a wrench in that by making the
internal array the HashBagOStuff use for storage have a specific schema, rather
than being a simple naive associative array.

But we don't have to do it that way; we could instead simply use two arrays --
one for values, the other for expiries.

Change-Id: I1f14c3578c2943df7560b6f51dec4db0b8c2d2f6
---
M includes/libs/objectcache/HashBagOStuff.php
1 file changed, 8 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/97/250297/1

diff --git a/includes/libs/objectcache/HashBagOStuff.php 
b/includes/libs/objectcache/HashBagOStuff.php
index bdcf180..d405a02 100644
--- a/includes/libs/objectcache/HashBagOStuff.php
+++ b/includes/libs/objectcache/HashBagOStuff.php
@@ -31,11 +31,10 @@
 class HashBagOStuff extends BagOStuff {
        /** @var mixed[] */
        protected $bag = array();
+       /** @var integer[] */
+       protected $expiries = array();
        /** @var integer Max entries allowed */
        protected $maxCacheKeys;
-
-       const KEY_VAL = 0;
-       const KEY_EXP = 1;
 
        /**
         * @param array $params Additional parameters include:
@@ -49,8 +48,7 @@
        }
 
        protected function expire( $key ) {
-               $et = $this->bag[$key][self::KEY_EXP];
-               if ( $et == 0 || $et > time() ) {
+               if ( empty( $this->expiries[$key] ) || $this->expiries[$key] > 
time() ) {
                        return false;
                }
 
@@ -68,19 +66,16 @@
                        return false;
                }
 
-               return $this->bag[$key][self::KEY_VAL];
+               return $this->bag[$key];
        }
 
        public function set( $key, $value, $exptime = 0, $flags = 0 ) {
-               $this->bag[$key] = array(
-                       self::KEY_VAL => $value,
-                       self::KEY_EXP => $this->convertExpiry( $exptime )
-               );
+               $this->bag[$key] = $value;
+               $this->expiries[$key] = $this->convertExpiry( $exptime );
 
                if ( count( $this->bag ) > $this->maxCacheKeys ) {
                        reset( $this->bag );
-                       $evictKey = key( $this->bag );
-                       unset( $this->bag[$evictKey] );
+                       $this->delete( key( $this->bag ) );
                }
 
                return true;
@@ -88,6 +83,7 @@
 
        public function delete( $key ) {
                unset( $this->bag[$key] );
+               unset( $this->expiries[$key] );
 
                return true;
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/250297
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1f14c3578c2943df7560b6f51dec4db0b8c2d2f6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to