MediaWiki REL1_33
WinCacheBagOStuff.php
Go to the documentation of this file.
1<?php
31 protected function doGet( $key, $flags = 0, &$casToken = null ) {
32 $casToken = null;
33
34 $blob = wincache_ucache_get( $key );
35 if ( !is_string( $blob ) ) {
36 return false;
37 }
38
40 if ( $value !== false ) {
41 $casToken = (string)$blob; // don't bother hashing this
42 }
43
44 return $value;
45 }
46
47 protected function cas( $casToken, $key, $value, $exptime = 0, $flags = 0 ) {
48 if ( !wincache_lock( $key ) ) { // optimize with FIFO lock
49 return false;
50 }
51
52 $curCasToken = null; // passed by reference
53 $this->doGet( $key, self::READ_LATEST, $curCasToken );
54 if ( $casToken === $curCasToken ) {
55 $success = $this->set( $key, $value, $exptime, $flags );
56 } else {
57 $this->logger->info(
58 __METHOD__ . ' failed due to race condition for {key}.',
59 [ 'key' => $key ]
60 );
61
62 $success = false; // mismatched or failed
63 }
64
65 wincache_unlock( $key );
66
67 return $success;
68 }
69
70 public function set( $key, $value, $expire = 0, $flags = 0 ) {
71 $result = wincache_ucache_set( $key, serialize( $value ), $expire );
72
73 // false positive, wincache_ucache_set returns an empty array
74 // in some circumstances.
75 // @phan-suppress-next-line PhanTypeComparisonToArray
76 return ( $result === [] || $result === true );
77 }
78
79 public function add( $key, $value, $exptime = 0, $flags = 0 ) {
80 $result = wincache_ucache_add( $key, serialize( $value ), $exptime );
81
82 // false positive, wincache_ucache_add returns an empty array
83 // in some circumstances.
84 // @phan-suppress-next-line PhanTypeComparisonToArray
85 return ( $result === [] || $result === true );
86 }
87
88 public function delete( $key, $flags = 0 ) {
90
91 return true;
92 }
93
102 public function makeKeyInternal( $keyspace, $args ) {
103 // WinCache keys have a maximum length of 150 characters. From that,
104 // subtract the number of characters we need for the keyspace and for
105 // the separator character needed for each argument. To handle some
106 // custom prefixes used by thing like WANObjectCache, limit to 125.
107 // NOTE: Same as in memcached, except the max key length there is 255.
108 $charsLeft = 125 - strlen( $keyspace ) - count( $args );
109
111 function ( $arg ) use ( &$charsLeft ) {
112 // 33 = 32 characters for the MD5 + 1 for the '#' prefix.
113 if ( $charsLeft > 33 && strlen( $arg ) > $charsLeft ) {
114 $arg = '#' . md5( $arg );
115 }
116
117 $charsLeft -= strlen( $arg );
118 return $arg;
119 },
120 $args
121 );
122
123 if ( $charsLeft < 0 ) {
124 return $keyspace . ':BagOStuff-long-key:##' . md5( implode( ':', $args ) );
125 }
126
127 return $keyspace . ':' . implode( ':', $args );
128 }
129
136 public function incr( $key, $value = 1 ) {
137 if ( !wincache_lock( $key ) ) { // optimize with FIFO lock
138 return false;
139 }
140
141 $n = $this->doGet( $key );
142 if ( $this->isInteger( $n ) ) {
143 $n = max( $n + (int)$value, 0 );
144 $oldTTL = wincache_ucache_info( false, $key )["ucache_entries"][1]["ttl_seconds"];
145 $this->set( $key, $n, $oldTTL );
146 } else {
147 $n = false;
148 }
149
150 wincache_unlock( $key );
151
152 return $n;
153 }
154}
serialize()
unserialize( $serialized)
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
if( $line===false) $args
Definition cdb.php:64
Class representing a cache/ephemeral data store.
Definition BagOStuff.php:58
isInteger( $value)
Check if a value is an integer.
string $keyspace
Definition BagOStuff.php:64
Wrapper for WinCache object caching functions; identical interface to the APC wrapper.
doGet( $key, $flags=0, &$casToken=null)
incr( $key, $value=1)
Increase stored value of $key by $value while preserving its original TTL.
makeKeyInternal( $keyspace, $args)
Construct a cache key.
add( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
cas( $casToken, $key, $value, $exptime=0, $flags=0)
Check and set an item.
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition hooks.txt:181