merging latest master
[lhc/web/wiklou.git] / includes / objectcache / BagOStuff.php
index e6ba042..fcc3aa9 100644 (file)
@@ -153,6 +153,7 @@ abstract class BagOStuff {
        /**
         * @param $key string
         * @param $value mixed
+        * @param $exptime int
         * @return bool success
         */
        public function replace( $key, $value, $exptime = 0 ) {
@@ -166,7 +167,7 @@ abstract class BagOStuff {
         * @param $key String: Key to increase
         * @param $value Integer: Value to add to $key (Default 1)
         * @return null if lock is not possible else $key value increased by $value
-        * @return success
+        * @return bool success
         */
        public function incr( $key, $value = 1 ) {
                if ( !$this->lock( $key ) ) {
@@ -215,4 +216,23 @@ abstract class BagOStuff {
                        return $exptime;
                }
        }
+
+       /**
+        * Convert an optionally absolute expiry time to a relative time. If an 
+        * absolute time is specified which is in the past, use a short expiry time.
+        *
+        * @param $exptime integer
+        * @return integer
+        */
+       protected function convertToRelative( $exptime ) {
+               if ( $exptime >= 86400 * 3650 /* 10 years */ ) {
+                       $exptime -= time();
+                       if ( $exptime <= 0 ) {
+                               $exptime = 1;
+                       }
+                       return $exptime;
+               } else {
+                       return $exptime;
+               }
+       }
 }