Skip to content

Commit b05377d

Browse files
2.13
1 parent 1dfedd3 commit b05377d

File tree

6 files changed

+66
-28
lines changed

6 files changed

+66
-28
lines changed

README.md

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,13 @@ or an entire group of elements.
88

99
[![Packagist](https://img.shields.io/packagist/v/eftec/CacheOne.svg)](https://packagist.org/packages/eftec/CacheOne)
1010
[![Total Downloads](https://poser.pugx.org/eftec/CacheOne/downloads)](https://packagist.org/packages/eftec/CacheOne)
11-
[![Maintenance](https://img.shields.io/maintenance/yes/2022.svg)]()
11+
[![Maintenance](https://img.shields.io/maintenance/yes/2023.svg)]()
1212
[![composer](https://img.shields.io/badge/composer-%3E1.6-blue.svg)]()
1313
[![php](https://img.shields.io/badge/php-7.2-green.svg)]()
1414
[![php](https://img.shields.io/badge/php-8.0-green.svg)]()
1515
[![php](https://img.shields.io/badge/php-8.1-green.svg)]()
1616
[![CocoaPods](https://img.shields.io/badge/docs-70%25-yellow.svg)]()
1717

18-
- [CacheOne](#cacheone)
19-
* [Example](#example)
20-
* [Creating a new instance of CacheOne](#creating-a-new-instance-of-cacheone)
21-
* [Storing a value](#storing-a-value)
22-
* [Getting a value](#getting-a-value)
23-
* [invalidate a key](#invalidate-a-key)
24-
* [invalidate a group](#invalidate-a-group)
25-
* [invalidate all](#invalidate-all)
26-
* [Select a database (Redis/PdoOne)](#select-a-database-redispdoone)
27-
- [Version](#version)
28-
- [License](#license)
29-
30-
3118

3219
# Example
3320

@@ -48,6 +35,32 @@ if($cacheValue===false) {
4835
var_dump($countries);
4936
```
5037

38+
# Table of Contents
39+
40+
<!-- TOC -->
41+
* [CacheOne](#cacheone)
42+
* [Example](#example)
43+
* [Table of Contents](#table-of-contents)
44+
* [Definitions](#definitions)
45+
* [Creating a new instance of CacheOne](#creating-a-new-instance-of-cacheone)
46+
* [Storing a value](#storing-a-value)
47+
* [Getting a value](#getting-a-value)
48+
* [setDefaultTTL](#setdefaultttl)
49+
* [Pushing and Popping values form an array](#pushing-and-popping-values-form-an-array)
50+
* [push](#push)
51+
* [unshift](#unshift)
52+
* [pop](#pop)
53+
* [shift](#shift)
54+
* [invalidate a key](#invalidate-a-key)
55+
* [invalidate a group](#invalidate-a-group)
56+
* [invalidate all](#invalidate-all)
57+
* [setSerializer($serializer)](#setserializer--serializer-)
58+
* [getSerializer();](#getserializer---)
59+
* [Select a database (Redis/PdoOne)](#select-a-database--redispdoone-)
60+
* [Version](#version)
61+
* [License](#license)
62+
<!-- TOC -->
63+
5164
# Definitions
5265

5366

@@ -293,7 +306,8 @@ $cache->select('table'); // PdoOne
293306
```
294307

295308
# Version
296-
309+
* 2.13
310+
* **[redis]** fixed a problem with redis and get()
297311
* 2.12.4
298312
* **[fixed]** solved a problem when the cache is not found.
299313
* 2.12.3

lib/CacheOne.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Class CacheOne
2121
*
2222
* @package eftec
23-
* @version 2.12.2
23+
* @version 2.13
2424
* @link https://github.com/EFTEC/CacheOne
2525
* @author Jorge Patricio Castro Castillo <jcastro arroba eftec dot cl>
2626
* @license Dual License: Commercial and MIT
@@ -216,7 +216,11 @@ public static function fixCast(&$destination, $source): void
216216
*/
217217
public function select($dbindex): void
218218
{
219-
$this->service->select($dbindex);
219+
try {
220+
$this->service->select($dbindex);
221+
} catch (Exception $e) {
222+
throw new RuntimeException("Error in CacheOne selecting database $dbindex, message:".$e->getMessage());
223+
}
220224
}
221225

222226
/**
@@ -318,7 +322,7 @@ public function invalidateAll(): bool
318322
* @return mixed
319323
* @throws Exception
320324
* @throws Exception
321-
* @see \eftec\CacheOne::getValue
325+
* @see CacheOne::getValue
322326
*/
323327
public function getCache(string $key, $family = '')
324328
{
@@ -360,12 +364,12 @@ public function getValue(string $key, $defaultValue = PHP_INT_MAX)
360364
* @return array|false|mixed|string|null
361365
* @throws Exception
362366
* @throws Exception
363-
* @see \eftec\CacheOne::getValue
367+
* @see CacheOne::getValue
364368
*/
365369
public function get($group, string $key, $defaultValue = PHP_INT_MAX)
366370
{
367371
// $this->resetStack();
368-
return $this->getValue($key, $defaultValue === PHP_INT_MAX ? $this->defaultValue : $defaultValue);
372+
return $this->getValue($key, $defaultValue); // === PHP_INT_MAX ? $this->defaultValue : $defaultValue);
369373
}
370374

371375
/**
@@ -416,7 +420,7 @@ public function setSerializer(string $serializer): CacheOne
416420
*
417421
* @return bool
418422
* @throws Exception
419-
* @see \eftec\CacheOne::set
423+
* @see CacheOne::set
420424
*/
421425
public function setCache(string $key, $family = '', $data = null, ?int $duration = null): bool
422426
{
@@ -750,7 +754,7 @@ public function serialize($input)
750754
*
751755
* @return bool
752756
* @throws Exception
753-
* @see \eftec\CacheOne::invalidate
757+
* @see CacheOne::invalidate
754758
*
755759
*/
756760
public function invalidateCache(string $key = '', $family = ''): bool

lib/provider/CacheOneProviderDocumentOne.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct($parent,$server,$schema)
2828

2929
$this->documentOne=new DocumentStoreOne($server,$schema);
3030
$this->parent->enabled=true;
31-
$this->documentOne->autoSerialize(true);
31+
$this->documentOne->autoSerialize();
3232

3333
}
3434
public function getInstance(): DocumentStoreOne
@@ -58,7 +58,7 @@ public function invalidateGroup(array $group) : bool
5858

5959
public function invalidateAll() : bool
6060
{
61-
$keys=$this->documentOne->select('*',true);
61+
$keys=$this->documentOne->select();
6262
$r=true;
6363
foreach($keys as $k) {
6464
$r=$r && $this->documentOne->delete($k);
@@ -123,7 +123,7 @@ public function set(string $uid, array $groups, string $key, $value, int $durati
123123
}
124124
$r=$this->documentOne->insertOrUpdate($uid, $value);
125125
if($duration===0) {
126-
$this->documentOne->setTimeStamp($uid, 1, true);
126+
$this->documentOne->setTimeStamp($uid, 1);
127127
} else {
128128
$this->documentOne->setTimeStamp($uid, $duration, false);
129129
}

lib/provider/CacheOneProviderPdoOne.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
)
3939
{
4040
$this->parent = $parent;
41-
$this->pdoOne = PdoOne::instance(true);
41+
$this->pdoOne = PdoOne::instance();
4242
$this->parent->schema = $schema;
4343
$this->parent->enabled = true;
4444
}

lib/provider/CacheOneProviderRedis.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use eftec\CacheOne;
88
use Exception;
99
use Redis;
10+
use RedisException;
1011

1112
class CacheOneProviderRedis implements ICacheOneProvider
1213
{
@@ -67,6 +68,9 @@ public function getInstance(): ?object
6768
return $this->redis;
6869
}
6970

71+
/**
72+
* @throws Exception
73+
*/
7074
public function invalidateGroup(array $group) : bool
7175
{
7276
$numDelete = 0;
@@ -87,6 +91,9 @@ public function invalidateGroup(array $group) : bool
8791
return $numDelete > 0;
8892
}
8993

94+
/**
95+
* @throws Exception
96+
*/
9097
public function invalidateAll(): bool
9198
{
9299
if ($this->redis === null) {
@@ -104,13 +111,20 @@ public function invalidateAll(): bool
104111
return false;
105112
}
106113

114+
/**
115+
* @throws Exception
116+
*/
107117
public function get(string $key, $defaultValue = false)
108118
{
109119
$uid = $this->parent->genId($key);
110-
$r = $this->parent->unserialize($this->redis->get($uid));
120+
$valueUnserialized=$this->redis->get($uid);
121+
$r = $this->parent->unserialize($valueUnserialized===false?null:$valueUnserialized);
111122
return $r ?? $defaultValue;
112123
}
113124

125+
/**
126+
* @throws Exception
127+
*/
114128
public function set(string $uid, array $groups, string $key, $value, int $duration = 1440): bool
115129
{
116130
if (count($groups) === 0) {
@@ -148,6 +162,9 @@ public function set(string $uid, array $groups, string $key, $value, int $durati
148162
return $this->redis->set($uid, $this->parent->serialize($value), $duration);
149163
}
150164

165+
/**
166+
* @throws Exception
167+
*/
151168
public function invalidate(string $group = '', string $key = ''): bool
152169
{
153170
$uid = $this->parent->genId($key);
@@ -158,6 +175,9 @@ public function invalidate(string $group = '', string $key = ''): bool
158175
return ($num > 0);
159176
}
160177

178+
/**
179+
* @throws Exception
180+
*/
161181
public function select($dbindex) : void
162182
{
163183
$this->redis->select($dbindex);

test/CacheOneTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private function runMe($type, $schema, $serializer='php', $server='127.0.0.1'):
138138

139139
$cache->invalidateAll();
140140
$class=strtolower($cache->getInstanceProvider()===null ? '' : get_class($cache->getInstanceProvider()));
141-
if($type!=='apcu' && $type!=='documentone' && $type!=='auto') {
141+
if($type!=='apcu' && $type!=='documentone' && $type!=='auto' && $type!=='memcache' ) {
142142
self::assertStringContainsString($type,$class);
143143
}
144144

0 commit comments

Comments
 (0)