-
Notifications
You must be signed in to change notification settings - Fork 0
FAQ
- Local development / small sites: File — zero setup.
- You already run a database, no extra service wanted: PDO.
- Hot, shared cache across servers: Redis or Memcache(d).
- WinCache: don't — it's deprecated and unavailable on PHP 8.
See the comparison table on the Home page.
Yes. Every handler implements Psr\SimpleCache\CacheInterface (via
CacheInterface), so you can use it anywhere a
PSR-16 cache is expected, and the package provides
psr/simple-cache-implementation.
Yes — any serialisable value round-trips exactly. Because get() also returns
its default on a miss, use has() to tell a stored null from a miss. See
Keys, TTL & Values.
The key was empty or contained a PSR-16 reserved character ({}()/\@:). Common
culprits are : (e.g. user:42) and /. Use . or _ instead, or hash
untrusted input. See Keys, TTL & Values.
It deletes the item (it's already expired), and set() returns true. Use
null for "no expiry". See TTL.
It depends on the backend:
-
File and PDO clear only items with the handler's
prefix. -
Redis runs
FLUSHDB(the whole selected database) and Memcache(d)/WinCache flush the whole store.
For Redis, isolate with a dedicated database; for Memcached, a dedicated
instance.
No. They are uniform across handlers but implemented as read-modify-write, so they can race under concurrency. For strict atomic counters, use the backend's native command in its own keyspace. See Counters.
No — increment()/decrement() store the new value without an expiry. If you
need a windowed counter, manage the TTL with set(). See the
soft rate limiter.
Yes: setOptions(['key' => 'value']) merges (case-insensitively) and returns the
handler. Read one back with getOption('key', $default). See
The Cache Factory.
No. Create the table yourself with the schema for your database; the
PDO Handler page has ready-made CREATE TABLE
statements for MySQL, SQLite and PostgreSQL.
The File handler needs nothing beyond PHP core, and
PDO needs only ext-pdo. The Redis and Memcache handlers need
their respective C extensions. Pre-check with isSupported() and fall back. See
Installation.
Use a small in-memory handler (or the File handler with a temp dir). See Testing.
Yes — extend BaseHandler and implement six
methods. See Custom Handlers.
- Troubleshooting — symptoms and fixes.
- Open an issue.
initphp/cache · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Core Concepts
Handlers
Guides
Other