Skip to content

Commit 777064f

Browse files
committed
minor fixes
1 parent 8c04dd3 commit 777064f

File tree

7 files changed

+31
-37
lines changed

7 files changed

+31
-37
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- exists() uses cached select path when not locked
1515
- Added invalidation for insertUsing/insertOrIgnoreUsing/updateFrom
1616
- Tag sets self-heal on cache hits (idempotent SADD)
17+
- Cache::flush() prefers non-blocking UNLINK (falls back to DEL)
1718

1819
### Fixed
1920
- No Redis initialization when disabled; flush command is a no-op when inactive

src/Cache.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,14 @@ public function flush(): void
8383
do {
8484
[$cursor, $keys] = $this->redis->scan($cursor, 'MATCH', $pattern, 'COUNT', 1000);
8585
if (! empty($keys)) {
86-
$this->redis->del(...$keys);
86+
// Prefer non-blocking UNLINK when available; fall back to DEL.
87+
try {
88+
$this->redis->unlink(...$keys);
89+
} catch (Throwable) {
90+
$this->redis->del(...$keys);
91+
}
8792
}
88-
} while ($cursor !== '0' && $cursor !== 0);
93+
} while ($cursor !== '0');
8994
} catch (Throwable $e) {
9095
Log::warning('[LadaCache] Redis flush failed: '.$e->getMessage());
9196
}

src/Encoder.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
* Encodes and decodes cache payloads for storage.
1414
*
1515
* Strategy:
16-
* - Scalars, arrays, and null are encoded as JSON (with exceptions on error) to keep
17-
* values portable and human-inspectable across services.
18-
* - Other values (e.g., objects) fall back to PHP's native serialization to retain
19-
* fidelity for framework- or application-specific types.
16+
* - Arrays are encoded via PHP's native serialization to preserve complex nested
17+
* structures and prevent ambiguity with JSON objects vs arrays when decoding.
18+
* - Scalars and null are encoded as JSON (throwing on errors) to remain compact,
19+
* portable, and human-inspectable.
20+
* - Objects attempt JSON encoding first to support simple DTO-like objects; if
21+
* that fails, fall back to native serialization for full fidelity.
2022
*
2123
* Architectural notes:
2224
* - The class is immutable and stateless; marked as readonly for clarity.
23-
* - Decoding first attempts JSON, then falls back to unserialize; if both fail,
24-
* null is returned to indicate an un-decodable payload.
25+
* - Decoding tries JSON first, then unserialize(); if both fail, returns null.
2526
*/
2627
final readonly class Encoder
2728
{
@@ -35,7 +36,6 @@ public function encode(mixed $data): string
3536
}
3637

3738
// For objects, prefer JSON to enable safe round-tripping of simple public data structures
38-
// (e.g., anonymous classes with public properties). If JSON encoding fails, fall back to
3939
// native serialization for complex framework types.
4040
try {
4141
return json_encode($data, JSON_THROW_ON_ERROR);

src/LadaCacheServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function boot(): void
6666
/**
6767
* {@inheritDoc}
6868
*/
69-
public function register()
69+
public function register(): void
7070
{
7171
$this->mergeConfigFrom(
7272
__DIR__.'/../config/'.self::CONFIG_FILE,
@@ -84,7 +84,7 @@ public function register()
8484
/**
8585
* {@inheritDoc}
8686
*/
87-
public function provides()
87+
public function provides(): array
8888
{
8989
return [
9090
'lada.redis',

src/Manager.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,12 @@ private function tablesCacheable(): bool
5050
return true;
5151
}
5252

53-
// Inclusive mode → all must be explicitly listed
53+
// Inclusive mode: every referenced table must be present in includeTables
5454
if ($this->includeTables !== []) {
55-
foreach ($tables as $table) {
56-
if (! in_array($table, $this->includeTables, true)) {
57-
return false;
58-
}
59-
}
60-
61-
return true;
62-
}
63-
64-
// Exclusive mode → none may appear in the blacklist
65-
foreach ($tables as $table) {
66-
if (in_array($table, $this->excludeTables, true)) {
67-
return false;
68-
}
55+
return array_diff($tables, $this->includeTables) === [];
6956
}
7057

71-
return true;
58+
// Exclusive mode: no referenced table may appear in excludeTables
59+
return array_intersect($tables, $this->excludeTables) === [];
7260
}
7361
}

src/QueryHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public function collectSubQueryTags(): void
7070
}
7171

7272
/**
73-
* @param string $statementType One of Reflector::QUERY_TYPE_*
74-
* @param array<string, mixed> $values Values used by the grammar to compile the SQL (e.g., update sets)
73+
* @param string $statementType One of Reflector::QUERY_TYPE_*
74+
* @param array<string, mixed> $values Values used by the grammar to compile the SQL (e.g., update sets)
7575
*/
7676
public function invalidateQuery(string $statementType, array $values = []): void
7777
{
@@ -105,6 +105,7 @@ public function invalidateQuery(string $statementType, array $values = []): void
105105

106106
// We can't know hashes before flushing; record action only.
107107
$this->stopCollector($reflector, $tags, [], "Invalidation queued ({$statementType})");
108+
108109
return;
109110
}
110111

src/Tagger.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,22 @@ private function prefix(string|array $value, string $prefix): string|array
117117
if (is_array($value)) {
118118
$out = [];
119119
foreach ($value as $item) {
120-
if (is_scalar($item) || is_string($item)) {
121-
$out[] = (string) $this->prefix((string) $item, $prefix);
120+
if (is_scalar($item)) {
121+
$out[] = $prefix.(string) $item;
122122

123123
continue;
124124
}
125125
if (is_object($item) && method_exists($item, '__toString')) {
126-
$out[] = (string) $this->prefix((string) $item, $prefix);
126+
$out[] = $prefix.(string) $item;
127+
128+
continue;
127129
}
128-
// Otherwise skip unstringable items (e.g., Query Expressions). Reflector should already
129-
// have provided normalized string table names for tagging purposes.
130+
// Skip unstringable items (e.g., Query Expressions). TableExtractor already normalizes names.
130131
}
131132

132133
return $out;
133134
}
134135

135-
$normalized = preg_replace('/\s+as\s+\w+$/i', '', (string) $value);
136-
137-
return $prefix.(string) $normalized;
136+
return $prefix.$value;
138137
}
139138
}

0 commit comments

Comments
 (0)