Download the PHP package migears/cache without Composer

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

migears/cache

Version

A lightweight PHP cache abstraction layer that provides a clean, unified API with in-memory array cache and Redis implementations.

Background: miGears is the open-source successor of TinyGears, a self-developed PHP framework. It was renamed and open-sourced recently because the name TinyGears is already taken in the open-source community.

Features

Boundaries

In scope

Not in scope (by design)

Installation

Using RedisCache requires the redis extension: pecl install redis

Quick Start

ArrayCache (In-Memory Cache)

An in-memory CacheInterface implementation for when no persistent store is needed:

Values live in a plain PHP array and are lost when the request ends; use RedisCache when data must be shared across requests or processes.

RedisCache

Passing an already connected Redis instance. RedisCache never connects on its own; establishing the connection belongs to the caller.

When using miGears in a web environment, inject the connection in MiRest and obtain it via the service registry:

Values are stored so that a string is never read back as something else. A string is written verbatim, unless it begins with an internal marker — then it is stored as a payload too, because the reader has no other way to tell the two apart. Only marked values are ever unserialized, so a string shaped like O:8:"stdClass":0:{} stays a string.

$allowedClasses bounds what a marked payload may instantiate on read. The default (true) keeps PSR-16 object support; pass false, or the classes you actually cache, if entries can be written by anyone outside your application:

With false, a payload carrying an object comes back as __PHP_Incomplete_Class instead of the object; arrays and scalars are unaffected.

API

Basic Methods

Method Description
get(string $key, mixed $default = null): mixed Get cache value
set(string $key, mixed $value, null\|int\|DateInterval $ttl = null): bool Set cache value
delete(string $key): bool Delete cache item
has(string $key): bool Check if cache exists
clear(): bool Clear all cache
getMultiple(iterable $keys, mixed $default = null): array Batch get
setMultiple(iterable $values, null\|int\|DateInterval $ttl = null): bool Batch set
deleteMultiple(iterable $keys): bool Batch delete
incr(string $key, int $step = 1): int Increment atomically
decr(string $key, int $step = 1): int Decrement atomically
getOrSet(string $key, callable $factory, $ttl = null): mixed Get or compute & store
withPrefix(string $prefix): static Return namespaced instance

A counter keeps the shape it was found in: one written by set() stays an int, so get() reads it back as an int, while a bare integer another client left behind stays a string. Both are adjusted inside one Redis script, so the read and the write cannot interleave, and the TTL survives.

A counter whose stored value is not an integer is refused rather than coerced: incr() and decr() throw CacheException (the value at "…" is not an integer). Both implementations answer the same way, so a counter does not change behaviour with the backend behind it, and a value overwritten by something non-numeric is never silently counted as 0. An integer string is an integer, as it is in Redis.

getOrSet — Lazy cache pattern

Compute and store a value only on cache miss:

Key Prefix — Namespacing

Isolate cache keys when sharing a backend across apps or modules:

⚠️ Redis clear() warning: When no prefix is set, clear() calls FLUSHDB which deletes all keys in the current Redis database. Use withPrefix() on shared Redis instances to avoid accidental data loss.

Cache Key Contract

PSR-16 reserves certain characters ({}()/\@:) and requires implementations to reject keys containing them with InvalidArgumentException. Both implementations validate every key and throw Psr\SimpleCache\InvalidArgumentException for a reserved character or a non-string key, so the array and Redis backends agree on what a key is. Keys may otherwise be any string; empty keys are accepted.

Redis Data Structures & Distributed Locks

Queue operations and distributed locks are not part of RedisCache; they live in the separate migears/data-structure package:

Logging

Supports injection of any PSR-3 compatible logging implementation:

Testing

Redis connection can be configured via environment variables:

License

MIT


migears/cache

Version

轻量级 PHP 缓存抽象层,提供简洁统一的 API,支持内存数组缓存和 Redis 实现。

特性

边界

范围内

范围外(刻意不做)

安装

使用 RedisCache 需要安装 redis 扩展:pecl install redis

快速开始

ArrayCache(内存缓存)

CacheInterface 的内存实现,适用于不需要持久化存储的场景:

数据存放在普通 PHP 数组中,请求结束即丢失;需要跨请求或跨进程共享数据时,请使用 RedisCache。

RedisCache

传入已连接的 Redis 实例。RedisCache 自身不会去连接,建立连接由调用方负责。

在 miGears 的 web 环境中,通过 MiRest 注入连接,再经服务注册中心取得:

存储方式是「无歧义」的:字符串原样写入,除非它以内部标记开头——那时它也会被当作载荷存储,因为读取方没有别的办法区分两者。只有带标记的值会被反序列化,因此形如 O:8:"stdClass":0:{} 的字符串读出来仍然是字符串。

$allowedClasses 限定读回时载荷可以实例化哪些类。默认值(true)保留 PSR-16 的对象支持;若缓存条目可能由应用之外的人写入,可传 false,或只列出你确实会缓存的类:

传 false 时,带对象的载荷会以 __PHP_Incomplete_Class 返回而非该对象;数组与标量不受影响。

API

基础方法

方法 说明
get(string $key, mixed $default = null): mixed 获取缓存值
set(string $key, mixed $value, null\|int\|DateInterval $ttl = null): bool 设置缓存值
delete(string $key): bool 删除缓存项
has(string $key): bool 检查缓存是否存在
clear(): bool 清空所有缓存
getMultiple(iterable $keys, mixed $default = null): array 批量获取
setMultiple(iterable $values, null\|int\|DateInterval $ttl = null): bool 批量设置
deleteMultiple(iterable $keys): bool 批量删除
incr(string $key, int $step = 1): int 原子自增
decr(string $key, int $step = 1): int 原子自减
getOrSet(string $key, callable $factory, $ttl = null): mixed 获取或计算并存储
withPrefix(string $prefix): static 返回带前缀的实例

计数器的存储形状保持不变:由 set() 写入的计数读回来是 int,而其他客户端留下的裸整数仍读作字符串。两者都在同一段 Redis 脚本中调整,因此读写不会被插入,TTL 也会保留。

存着的值不是整数时,计数器会拒绝而不是强转:incr() 与 decr() 抛 CacheException(the value at "…" is not an integer)。两个实现给的是同一个答案,因此计数器的行为不会随背后的后端而变,被非数值覆盖过的值也绝不会被悄悄当成 0 来计数。整数字符串算整数,Redis 也是如此。

getOrSet — 懒缓存模式

只在缓存未命中时计算并存储值:

Key Prefix — 键命名空间

在共享后端上隔离不同应用/模块的缓存键:

⚠️ Redis clear() 注意:未设置前缀时,clear() 会调用 FLUSHDB 删除当前 Redis 数据库中所有键。在共享 Redis 实例上请使用 withPrefix() 避免误删数据。

缓存键约定

PSR-16 保留了一些字符({}()/\@:)并要求实现对其抛 InvalidArgumentException。两个实现都会校验每一个键,遇到保留字符或非字符串键时抛出 Psr\SimpleCache\InvalidArgumentException,从而使数组后端与 Redis 后端对「什么是合法的键」保持一致。除此之外键可以是任意字符串;空键允许使用。

Redis 数据结构与分布式锁

队列操作与分布式锁不属于 RedisCache,它们位于独立的 migears/data-structure 包中:

日志

支持注入任意 PSR-3 兼容的日志实现:

测试

Redis 连接可通过环境变量配置:

License

MIT


All versions of cache with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
psr/simple-cache Version ^3.0
psr/log Version ^3.0
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 migears/cache contains the following files

Loading the files please wait ...