nette-caching
БесплатноБез исполняемых скриптовНе проверенInvoke before writing or reviewing code that uses nette/caching. Covers the Cache object and namespaces, load() with a generator callback, save(), remove()…
от nette★ 47 звёзд на GitHubОб этом скилле
Nette Caching
composer require nette/caching
Version 4.0 requires PHP 8.4. What differs from 3.x is in Upgrading;
check the installed version before relying on Dependencies or named arguments of clean().
Dependencies
Since 4.0 dependencies are the object Nette\Caching\Dependencies with the properties expire,
sliding, tags, priority, files, items, constants and callbacks. A generator whose
parameter is typed Dependencies gets the object; an untyped one gets the array by reference.
use Nette\Caching\Cache;
use Nette\Caching\Dependencies;
$cache = new Cache($storage, 'articles'); // Nette\Caching\Storage is autowired
$sub = $cache->derive('previews'); // nested namespace
$html = $cache->load("article/$id", function (Dependencies $dp) use ($id) {
$dp->expire = '20 minutes';
$dp->tags = ["article/$id"];
return renderArticle($id);
});
$cache->save($key, $value, new Dependencies(expire: '1 hour', tags: ['articles']));
The array form with Cache::* keys still works. Since 4.0 an unknown key or a wrong type throws,
typically a priority written as the string '50'. The constants are PascalCase:
Cache::Expire // 'expire' – NOT Cache::Expiration (that constant does not exist)
Cache::Sliding // 'sliding'
Cache::Tags // 'tags'
Cache::Files // 'files' – resolved with filemtime(), so a relative path depends on the CWD; use absolute
Cache::Items // 'items' – other cache keys
Cache::Constants // 'consts'
Cache::Callbacks // 'callbacks' – [callable, ...args], must return true to stay valid.
// The callable is SERIALIZED with the entry, so a closure is
// a fatal ("Serialization of 'Closure' is not allowed") –
// use a function name or [Class::class, 'method'].
Cache::Priority // 'priority' – int
Cache::EXPIRATION and the other UPPER_CASE names are deprecated aliases (E_USER_DEPRECATED
since 4.0); Cache::Expiration does not exist and is a fatal Undefined constant. There
is likewise no forget(), no delete() and no has() – removal is remove($key).
Reading and Writing
- Prefer
load()with a generator tosave(): only with a generator doFileStorageandRedisStorageprotect against cache stampede. If the generator throws, nothing is stored. A generator must notload()its own key:FileStoragethrowsInvalidStateException. load($key)without a generator returnsnullon a miss, sonullis not storable:save($key, null)removes the entry, as does anexpireresolving to<= 0.expireaccepts seconds, a UNIX timestamp, aDateTimeInterfaceor anyDateTime::from()string. Keys may be any serializable value, not just strings;save()returns the value.save()with a closure as the data is deprecated; useload().
Cleaning
$cache->clean(tags: ["article/$id"]); // in every namespace of the storage
$cache->clean(priority: 50); // priority <= 50; items without priority stay
$cache->clean(namespaces: ['articles']);
$cache->clean(all: true); // only this namespace and those derived from it
Since 4.0 clean() takes named arguments (3.x: clean([Cache::Tags => [...]]), which still
works). clean() with no condition throws; expired items are removed by $storage->clean([]).
all on a cache with a namespace no longer wipes the storage, only a cache without one does.
Storages and the Journal
A storage throws Nette\NotSupportedException for a dependency or condition it cannot honor
(3.x silently ignored them):
| Storage | Tags, priority | Files, constants, callbacks | Items | Sliding | Clean namespaces | Stampede |
|---|---|---|---|---|---|---|
FileStorage (default) |
journal | yes | yes | yes | yes | yes |
RedisStorage |
yes | yes | no | yes | yes | yes |
MemcachedStorage |
journal | yes | no | yes | no | no |
SQLiteStorage |
tags only | no | no | yes | yes | no |
MemoryStorage |
yes | ignored | ignored | yes | yes | no |
Psr16Storage |
journal | yes | no | no | no | no |
"journal": without one, a write with tags or priority throws
Nette\InvalidStateException: CacheJournal has not been provided. The default journal is
SQLiteJournal, and the DI extension registers it only if pdo_sqlite is loaded – without
that extension every tagged save() blows up at runtime. MemoryStorage silently ignores what it
cannot do, so in tests an item that would expire in production stays.
Nette\Bridges\Psr\PsrCacheAdapter exposes a storage as PSR-16 and since 4.0 rejects keys
containing {}()/\@: such as user:1; Psr16Storage is the opposite direction.
$values = $cache->bulkLoad($keys, fn($key, Dependencies $dp) => compute($key)); // scalar keys only
$cache->bulkSave([$k1 => $v1, $k2 => $v2], new
Установить nette-caching в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл nette-caching?
Invoke before writing or reviewing code that uses nette/caching. Covers the Cache object and namespaces, load() with a generator callback, save(), remove(), clean() with named conditions, the Dependencies object and the Cache::* dependency array (Expire, Tags, Files, Items, Priority, Sliding, Callbacks), the Journal requirement for tags and priorities, bulkLoad(), output capture, storages (FileStorage, RedisStorage, MemcachedStorage, SQLiteStorage, MemoryStorage, Psr16Storage, DevNullStorage), PSR-16 adapters and the {cache} Latte tag. Also trigger for cache.storage or cache.journal in NEON, invalidation by tag, cache stampede, or disabling the cache in tests. Not for the Latte template cache or the DI container cache, which are separate mechanisms.
Как установить скилл nette-caching?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл nette-caching запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic