Download the PHP package iviphp/cache without Composer

On this page you can find all versions of the php package iviphp/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

Ivi Cache

Cache stores and cache management for the IviPHP ecosystem.

Overview

iviphp/cache provides a small, framework-independent cache layer for PHP applications.

It includes:

The package currently provides two cache drivers:

Installation

Requirements

The filesystem store can optionally use the PHP Zlib extension for payload compression.

Package structure

Basic usage

Cache configuration

The recommended configuration structure contains a default store and a map of named stores:

The configured default store must exist.

Direct store configuration

A direct map of named stores is also accepted:

In this example, the store named default becomes the default cache store.

Array store

The array store keeps values in the current PHP process.

The array store is useful for:

Values disappear when the PHP process ends.

Objects are stored directly and retain their normal PHP reference behavior.

File store

The file store persists values on the filesystem.

The configured directory is created automatically by default.

The directory must be readable and writable by the PHP process.

File store configuration

Supported file-store options:

Option Default Description
directory required Filesystem cache directory
path none Alias of directory
allowed_classes false Classes allowed during serialization
compression_threshold 1024 Minimum serialized size before compression
compression_level 6 Zlib compression level from 0 to 9
maximum_entry_bytes 67108864 Maximum cache entry size
file_permissions 0600 Permissions applied to cache files
directory_permissions 0700 Permissions applied to cache directories
create_directory true Create the cache directory when missing

Storing values

Store a value for a limited time:

The integer lifetime is expressed in seconds.

Permanent values

Store a value without expiration:

The following call is equivalent:

Retrieving values

Provide a default value:

The default value is returned when the key:

Cached null values

Cached null values are treated as existing entries.

Use has() when the difference between a missing entry and a cached null value matters.

Checking existence

Expired entries are treated as missing.

Deleting values

Deleting a missing key is considered successful.

Retrieving and deleting

Use pull() to retrieve and remove a value:

After the operation, the key no longer exists.

Clearing a store

Clear the selected store:

For the file store, the root cache directory is preserved.

The global store-lock file is also preserved.

Clearing every store

Every registered store is resolved and cleared.

Remembering values

Retrieve an existing value or calculate and cache it:

The resolver runs only when the key does not exist or has expired.

Remembering permanent values

This value remains cached until it is explicitly deleted or the store is cleared.

DateInterval expiration

A DateInterval can be used instead of an integer:

Remember a value for one hour:

Immediate expiration

A lifetime of zero or fewer seconds removes the existing entry:

The value is not stored.

Multiple cache stores

Use the default store:

Use another store:

The original cache instance remains unchanged.

Return to the manager default:

Cache manager

Create a manager directly:

Create a cache entry point:

Resolving stores

Resolve the default store:

Resolve a named store:

get() is an alias of store():

Stores are resolved lazily and reused after their first creation.

Registering a store

Register a configured store:

Register an existing store instance:

Store factories

A closure can create a custom store lazily:

The factory must return an implementation of CacheInterface.

Replacing a store

The previously resolved store instance is discarded.

The new definition is resolved lazily.

Removing a store

When the removed store was the default, the first remaining registered store becomes the new default.

Store information

Check whether a store is registered:

Check whether it has already been resolved:

Return all registered store names:

Return the default store name:

Change the default store:

The store must already be registered.

Clearing resolved stores

Clear only stores that were already resolved:

Stores that have not yet been resolved are not created.

Clearing all registered stores

Every registered store is resolved and cleared.

Removing all definitions

This removes all registered definitions and resolved store instances.

It does not automatically clear persistent cache data before removing the definitions.

Using stores directly

ArrayStore

FileStore

Array-store inspection

The array store provides additional inspection methods.

Count unexpired entries:

Return all unexpired keys:

Remove expired entries:

File-store maintenance

The file store also provides maintenance methods.

Return the canonical cache directory:

Remove expired entries:

Count valid entries:

File storage format

File cache entries use:

Original cache keys are not used as filenames.

A key such as:

is converted to a SHA-256 hash before creating its storage path.

Atomic writes

The file store writes data to a temporary file before replacing the destination cache file.

This reduces the risk of partially written cache entries.

Per-key locks protect concurrent write operations for the same cache key.

Cache stampede protection

FileStore::remember() holds a per-key lock while resolving a missing value.

Concurrent processes requesting the same missing key wait for the first resolver instead of calculating the value simultaneously.

This protection applies to the filesystem store.

The array store is scoped to one PHP process and does not provide inter-process locking.

Compression

Serialized payloads larger than the configured threshold may be compressed:

Compression is only retained when the compressed payload is smaller than the original serialized payload.

When Zlib is unavailable, values are stored without compression.

Maximum entry size

The default maximum cache entry size is 64 MiB:

The limit protects the application from unexpectedly large cache files and decompressed payloads.

Caching objects

The file store disables object restoration by default:

This is the safest default when cache files could be modified outside the application.

Allow specific classes:

Allow every serialized class:

Allowing every class should only be used when the cache directory is fully trusted and protected.

Unsupported file-cache values

The file store rejects values that cannot be safely serialized, including:

The array store can keep closures and most runtime values because it does not serialize them.

Cache keys

Cache keys must:

Valid examples:

Keys are application-defined and may contain common separators.

Cache exceptions

Cache failures throw:

Example:

Safe exception context

CacheException provides diagnostic context without including cached values or serialized payloads.

Possible context fields include:

The original cache key is not included in serialization, read, write and deletion failure contexts.

Exception factories

Cache interface

Custom cache stores must implement:

The contract defines:

Custom cache store

Register the custom store:

Complete example

Security considerations

Protect the cache directory

The file cache directory must not be writable by untrusted users.

Recommended permissions:

The cache directory should not be publicly accessible through the web server.

Do not cache secrets unnecessarily

Avoid caching sensitive values unless required.

Examples include:

Serialized data

PHP serialized data must only be restored from trusted cache files.

The default file-store configuration disables object restoration:

Prefer arrays and scalar values for persistent cache entries.

Cache is not permanent storage

Cache data may be:

Do not use cache storage as the only source of important application data.

Cache keys are not authorization

The presence of a cache entry does not prove that a user is authorized to access the underlying data.

Authorization checks must remain in the application.

Design principles

Package boundaries

This package is responsible for:

It is not responsible for:

Additional cache drivers can be provided by separate IviPHP packages.

Current limitations

The initial release does not include:

These features can be added later without expanding the core package unnecessarily.

Ecosystem

This package is part of the IviPHP ecosystem:

Contributing

Contributions should preserve the focused and secure design of the package.

Changes should:

Security

Please report security vulnerabilities privately to the Softadastra maintainers instead of opening a public issue.

License

This project is licensed under the MIT License.

Maintainer

Created and maintained by Softadastra.


All versions of cache with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
iviphp/support Version ^0.1
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 iviphp/cache contains the following files

Loading the files please wait ...