Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.1
coverage: none

- run: composer install --no-progress --prefer-dist
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.0', '8.1', '8.2', '8.3', '8.4']
php: ['8.1', '8.2', '8.3', '8.4']

fail-fast: false

Expand Down Expand Up @@ -37,7 +37,7 @@ jobs:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.1
coverage: none

- run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable
Expand All @@ -52,7 +52,7 @@ jobs:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.1
coverage: none

- run: composer install --no-progress --prefer-dist
Expand Down
17 changes: 10 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,28 @@
}
],
"require": {
"php": "8.0 - 8.4",
"php": "8.1 - 8.4",
"nette/utils": "^4.0"
},
"require-dev": {
"nette/tester": "^2.4",
"nette/di": "^3.1 || ^4.0",
"latte/latte": "^2.11 || ^3.0.12",
"latte/latte": "^3.0.12",
"tracy/tracy": "^2.9",
"phpstan/phpstan": "^1.0",
"psr/simple-cache": "^2.0 || ^3.0"
"psr/simple-cache": "^2.0 || ^3.0",
"phpstan/phpstan-nette": "^2.0@stable"
},
"conflict": {
"latte/latte": ">=3.0.0 <3.0.12"
"latte/latte": "<3.0.12"
},
"suggest": {
"ext-pdo_sqlite": "to use SQLiteStorage or SQLiteJournal"
},
"autoload": {
"classmap": ["src/"]
"classmap": ["src/"],
"psr-4": {
"Nette\\": "src"
}
},
"minimum-stability": "dev",
"scripts": {
Expand All @@ -42,7 +45,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.3-dev"
"dev-master": "4.0-dev"
}
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Installation
composer require nette/caching
```

It requires PHP version 8.0 and supports PHP up to 8.4.
It requires PHP version 8.1 and supports PHP up to 8.4.


Basic Usage
Expand Down
8 changes: 0 additions & 8 deletions src/Bridges/CacheDI/CacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,5 @@ public function loadConfiguration(): void
$builder->addDefinition($this->prefix('storage'))
->setType(Nette\Caching\Storage::class)
->setFactory(Nette\Caching\Storages\FileStorage::class, [$this->tempDir]);

if ($this->name === 'cache') {
if (extension_loaded('pdo_sqlite')) {
$builder->addAlias('nette.cacheJournal', $this->prefix('journal'));
}

$builder->addAlias('cacheStorage', $this->prefix('storage'));
}
}
}
168 changes: 0 additions & 168 deletions src/Bridges/CacheLatte/CacheMacro.php

This file was deleted.

1 change: 1 addition & 0 deletions src/Bridges/CacheLatte/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Nette;
use Nette\Caching\Cache;
use Nette\Caching\OutputHelper;
use function array_intersect_key, array_key_exists, array_merge, array_pop, count, end, is_file, range;


/**
Expand Down
8 changes: 4 additions & 4 deletions src/Caching/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Nette\Caching;

use Nette;
use function array_keys, array_map, array_shift, array_slice, array_unique, array_values, constant, count, defined, filemtime, func_get_args, get_class, is_array, is_object, is_scalar, md5, serialize, substr, time;


/**
Expand Down Expand Up @@ -64,9 +65,7 @@ class Cache
public const ALL = self::All;

/** @internal */
public const
NamespaceSeparator = "\x00",
NAMESPACE_SEPARATOR = self::NamespaceSeparator;
public const NamespaceSeparator = "\x00";

private Storage $storage;
private string $namespace;
Expand Down Expand Up @@ -385,6 +384,7 @@ public function capture(mixed $key): ?OutputHelper
*/
public function start($key): ?OutputHelper
{
trigger_error(__METHOD__ . '() was renamed to capture()', E_USER_DEPRECATED);
return $this->capture($key);
}

Expand All @@ -394,7 +394,7 @@ public function start($key): ?OutputHelper
*/
protected function generateKey($key): string
{
return $this->namespace . md5(is_scalar($key) ? (string) $key : serialize($key));
return $this->namespace . hash('xxh128', is_scalar($key) ? (string) $key : serialize($key));
}


Expand Down
3 changes: 1 addition & 2 deletions src/Caching/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ interface Storage
{
/**
* Read from cache.
* @return mixed
*/
function read(string $key);
function read(string $key): mixed;

/**
* Prevents item reading and writing. Lock is released by write() or remove().
Expand Down
4 changes: 3 additions & 1 deletion src/Caching/Storages/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

use Nette;
use Nette\Caching\Cache;
use function dirname, fclose, filemtime, flock, fopen, fseek, ftruncate, fwrite, is_dir, is_string, microtime, mkdir, mt_getrandmax, mt_rand, rmdir, serialize, str_pad, str_repeat, stream_get_contents, strlen, strrpos, substr_replace, time, touch, unlink, unserialize, urlencode;
use const LOCK_EX, LOCK_SH, LOCK_UN, STR_PAD_LEFT;


/**
Expand All @@ -32,7 +34,7 @@ class FileStorage implements Nette\Caching\Storage
/** @internal cache file structure: meta-struct size + serialized meta-struct + data */
private const
MetaHeaderLen = 6,
// meta structure: array of
// meta structure: array of
MetaTime = 'time', // timestamp
MetaSerialized = 'serialized', // is content serialized?
MetaExpire = 'expire', // expiration timestamp
Expand Down
3 changes: 2 additions & 1 deletion src/Caching/Storages/MemcachedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Nette;
use Nette\Caching\Cache;
use function array_combine, array_map, extension_loaded, time, urlencode;


/**
Expand Down Expand Up @@ -105,7 +106,7 @@ public function bulkRead(array $keys): array
{
$prefixedKeys = array_map(fn($key) => urlencode($this->prefix . $key), $keys);
$keys = array_combine($prefixedKeys, $keys);
$metas = $this->memcached->getMulti($prefixedKeys);
$metas = $this->memcached->getMulti($prefixedKeys) ?: [];
$result = [];
$deleteKeys = [];
foreach ($metas as $prefixedKey => $meta) {
Expand Down
2 changes: 1 addition & 1 deletion src/Caching/Storages/SQLiteJournal.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Nette;
use Nette\Caching\Cache;
use function count, extension_loaded, implode, is_file, str_repeat, touch;


/**
Expand Down Expand Up @@ -40,7 +41,6 @@ private function open(): void
}

$this->pdo = new \PDO('sqlite:' . $this->path);
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->pdo->exec('
PRAGMA foreign_keys = OFF;
PRAGMA journal_mode = WAL;
Expand Down
Loading