Download the PHP package webfiori/cache without Composer

On this page you can find all versions of the php package webfiori/cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package cache

WebFiori Cache

A simple, secure, and highly customizable caching engine for PHP. This library provides time-based caching with built-in encryption support, making it suitable for application-level, server-level, and database-level caching scenarios.

Features

Installation

Supported PHP Versions

This library requires PHP 8.1 or higher.

Build Status

Quick Start

For a complete runnable version of this, see the Set and Get example.

Usage

Basic Operations

Working examples for each operation: basic examples

Prefix Isolation

withPrefix() returns a new Cache instance — the original is never mutated.

See Prefix Flush.

Static Facade

For quick usage without dependency injection, use CacheFacade:

Security & Encryption

Cached data is encrypted using AES-256-CBC when an encryption key is available. If no key is set, data is stored unencrypted. Configure via environment variables or programmatically:

See Encrypt/Decrypt Round-Trip.

Redis Storage

A built-in Redis backend is available via RedisStorage. It requires the ext-redis PHP extension and a connected \Redis instance:

Redis handles TTL natively, so expired items are removed automatically — no need for purgeExpired().

See Redis Storage for a full example.

Custom Storage Drivers

Implement the Storage interface to create custom backends (e.g., Memcached, database):

Full working implementation: Custom Storage Driver.

API Reference

Cache Class (Instance Methods)

Method Description Returns
get($key, $generator, $ttl, $params) Retrieve or create cache item mixed
set($key, $data, $ttl, $override) Store cache item bool
has($key) Check if item exists and is not expired bool
delete($key) Remove cache item void
flush() Clear all cache (respects current prefix) void
getItem($key) Get Item object with full metadata Item\|null
setTTL($key, $ttl) Update item TTL bool
isEnabled() / setEnabled($bool) Check or toggle caching bool / void
setDriver($driver) / getDriver() Set or get storage driver void / Storage
withPrefix($prefix) Returns new Cache instance with prefix Cache
getPrefix() Get current prefix string
purgeExpired() Remove all expired items from storage int

CacheFacade Class (Static Methods)

Same methods as Cache, plus:

Method Description Returns
getInstance() Get the default Cache instance Cache
setInstance($cache) Replace the default instance void
reset() Destroy the default instance (for testing) void

Item Class

Method Description Returns
getKey() Get item key string
getData() / getDataDecrypted() / getDataEncrypted() Get raw, decrypted, or encrypted data mixed / mixed / string
getTTL() / setTTL($ttl) Get or set time-to-live int / void
getCreatedAt() / getExpiryTime() Get creation or expiry timestamp int
getSecurityConfig() / setSecurityConfig($config) Get or set security configuration SecurityConfig / void
generateKey() Generate encryption key (static) string

Storage Interface

Method Description
store(Item $item) Store cache item
read(string $key, ?string $prefix) Read item data
readItem(string $key, ?string $prefix) Read item as Item object
has(string $key, ?string $prefix) Check item existence
delete(string $key) Delete item
flush(?string $prefix) Clear cache
purgeExpired() Remove expired items, return count removed

Error Handling

Exception When
InvalidCacheKeyException Empty key, key > 250 chars, key with control characters
CacheStorageException File system errors, invalid paths, permission issues
CacheDriverException Invalid driver implementation
CacheException Base exception, missing encryption key

See Error Handling for all cases.

Upgrading from v2

v3 changes Cache from a static singleton to an instance class. Migration is straightforward:

If you prefer the static API, use CacheFacade — it works identically to v2's Cache:

Examples

The examples/ directory contains 23 self-contained, runnable samples organized by difficulty:

Basic — Core operations every user needs:

# Example What it demonstrates
01 Set and Get set() and get()
02 Get with Generator Auto-populate on cache miss
03 Generator with Params Pass arguments to the callback
04 Check Existence has()
05 Delete Item delete()
06 Flush Cache flush()
07 Update TTL setTTL()
08 Override Behavior set() with/without override
09 TTL Expiration Items expire after TTL
10 Enable / Disable Toggle caching on/off
11 Item Inspection Read item metadata
12 Data Types Strings, arrays, objects, edge cases

Advanced — Security, extensibility, and error handling:

# Example What it demonstrates
01 Prefix Isolation Namespace isolation
02 Prefix Flush Selective flush by prefix
03 Encryption Key Management KeyManager usage
04 Security Config Algorithm and permissions
05 Encryption Disabled Store without encryption
06 Encrypt/Decrypt Round-Trip Full encryption cycle
07 Custom Storage Driver Implement Storage interface
08 File Storage Custom Path Custom cache directory
09 File Permissions Default and custom permissions
10 Error Handling All exception types
11 Factory and DI Constructor-based DI
12 Redis Storage Redis backend driver

Run any example:

License

This library is licensed under MIT License. See LICENSE file for more details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite: composer test
  6. Submit a pull request

Support


All versions of cache with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package webfiori/cache contains the following files

Loading the files please wait ...