3 * Object caching using PHP's APCU accelerator.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * This is a wrapper for APCU's shared memory functions
29 class APCUBagOStuff
extends APCBagOStuff
{
31 * Available parameters are:
32 * - nativeSerialize: If true, pass objects to apcu_store(), and trust it
33 * to serialize them correctly. If false, serialize
36 * @param array $params
38 public function __construct( array $params = [] ) {
39 parent
::__construct( $params );
42 protected function doGet( $key, $flags = 0 ) {
43 return $this->getUnserialize(
44 apcu_fetch( $key . self
::KEY_SUFFIX
)
48 public function set( $key, $value, $exptime = 0, $flags = 0 ) {
50 $key . self
::KEY_SUFFIX
,
51 $this->setSerialize( $value ),
58 public function add( $key, $value, $exptime = 0, $flags = 0 ) {
60 $key . self
::KEY_SUFFIX
,
61 $this->setSerialize( $value ),
66 public function delete( $key, $flags = 0 ) {
67 apcu_delete( $key . self
::KEY_SUFFIX
);
72 public function incr( $key, $value = 1 ) {
74 * @todo When we only support php 7 or higher remove this hack
76 * https://github.com/krakjoe/apcu/issues/166
78 if ( apcu_exists( $key . self
::KEY_SUFFIX
) ) {
79 return apcu_inc( $key . self
::KEY_SUFFIX
, $value );
85 public function decr( $key, $value = 1 ) {
87 * @todo When we only support php 7 or higher remove this hack
89 * https://github.com/krakjoe/apcu/issues/166
91 if ( apcu_exists( $key . self
::KEY_SUFFIX
) ) {
92 return apcu_dec( $key . self
::KEY_SUFFIX
, $value );