Download the PHP package laruence/yac without Composer

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

Yac - Yet Another Cache

AppVeyor Linux Windows Hammer

Yac is a lock-free shared-memory user data cache for PHP, dramatically faster than APCu and local Memcached under a realistic multi-worker load (see Benchmarks).

It can be used to replace APC or local memcached.

When to use Yac

Yac is a lockless, shared memory cache. It lives in the same process space as PHP (no network round-trip) and avoids coarse-grained locks — which means:

It is built for raw speed: get() is essentially a hash lookup in shared memory — microsecond-level latency.

Benchmarks

16 worker processes sharing one cache, mixed reads/writes at a 100:1 ratio, compression off, 160M shared memory for both Yac and APCu. Numbers are aggregate ops/s across all workers, one value size per run:

Value size Yac APCu 5.1.28 Memcached 3.4.0 Yac / APCu Yac / Memcached
6 B 77.1M 1.10M 0.11M 69.8x 726.7x
256 B 60.5M 1.12M 0.11M 54.0x 574.3x
2048 B 17.2M 1.28M 0.10M 13.4x 169.6x

Yac built from the current master. Measures throughput, not consistency. Environment and reproduction: bench/README.md.

Install

Requirement

Install via PECL

Install via PIE

PIE (PHP Installer for Extensions) downloads, builds and installs the extension from Packagist:

Optional serializers can be enabled at install time:

See PIE usage for more options (e.g. installing a specific version).

Compile from source

The optional --enable-msgpack, --enable-igbinary, and --enable-json flags enable the corresponding serializers. See Serializer below.

Important: CLI mode

Yac is disabled in CLI mode by default. If you are testing or running scripts from the command line, add this to your php.ini:

Otherwise new Yac() will throw an exception.

Note

  1. Yac is a lockless cache, you should try to avoid or reduce the probability of multiple processes setting the same key simultaneously.
  2. Yac checks every stored value with a full CRC-32C, so a corrupted or overwritten entry is detected and reported as a miss rather than returned.

Restrictions

  1. Cache key cannot be longer than 48 (YAC_MAX_KEY_LEN) bytes.
  2. Cache value cannot be longer than 67108863 (YAC_MAX_VALUE_RAW_LEN) bytes, i.e. (1 << 26) - 1.
  3. Cache value after compression cannot be longer than 1M (YAC_MAX_RAW_COMPRESSED_LEN) bytes.

INI Settings

Constants

Supported Data Types

Yac can store all PHP types except resources:

Type Notes
null Stored as-is; it comes back as NULL, while a miss returns false (or the default) — see Missing keys
bool Stored as-is; to tell a stored false apart from a miss, pass a default — see Missing keys
int / long Stored directly
float / double Stored directly
string Stored directly; compressed if larger than yac.compress_threshold
array Serialized (php/msgpack/igbinary/json), then compressed if needed
object Serialized and compressed same as array
resource Not supported — triggers a warning

Missing keys

Without a second argument, get() returns false for a key that does not exist (or that fails the integrity check) — the same value a stored false returns, so the two cases are indistinguishable by return value alone.

Since 2.4.0, get() accepts an optional default argument that is returned when the key is missing:

With a sentinel default, a miss can be told apart from every stored value, including stored false and stored NULL. The default is passed by value, so any expression works: get("n", 0), get("n", []), etc.

Methods

Yac::__construct

Constructor of Yac. You can specify a prefix which will be prepended to every key in subsequent set/get/delete calls.

The prefix is concatenated directly onto the key — no separator is added automatically. If you need a separator, include it in the prefix.

Throws an exception if:

Multi-tenant prefix example

Property Access

Yac also supports array-like property access, which maps directly to get/set/delete:

Note: Property access always uses set() semantics (overwrite), not add(). TTL is not supported through property access — if you need TTL or add semantics, call the method explicitly.

Yac::add

Similar to set, but only stores the value if the key does not already exist (memcached add semantics).

$ttl is the time-to-live in seconds. 0 means the value never expires.

Returns true on success, false if the key already exists or on error.

Yac::set

Store a value into Yac cache. Keys are cache-unique, so storing a second value with the same key will overwrite the original value.

$ttl is the time-to-live in seconds. 0 means the value never expires.

Returns true on success, false on error (e.g. cannot obtain CAS write lock).

Note

Since Yac 2.1, set() may fail if CAS competition occurs. For critical values, retry until success:

Yac::get

Fetches a stored variable from the cache.

For a single key, returns the cached value on success. On a miss (key does not exist, or integrity check fails) it returns $default if one was passed, otherwise false — see Missing keys.

For an array of keys, returns an array of the found key-value pairs. Missing keys are omitted from the result when no default is given, so the presence of a key in the returned array means it exists in the cache; when a default is given, each missing key is present in the result with the default as its value.

Note: Before 2.4.0, get() with an array of keys inserted a false placeholder for every missing key. Since 2.4.0 they are omitted (or filled with the given default) instead — code that reads $result[$key] without checking existence may now raise an undefined-key warning.

Yac::delete

Removes a stored variable from the cache. If $delay is specified (in seconds), the value will be deleted after $delay seconds — a delayed deletion.

Note: delete() is a logical deletion — it marks the entry as expired (sets its TTL to 1, or to a future timestamp for delayed deletion) but keeps the slot until the space is reclaimed on a future access. It does not immediately free memory.

Returns true on success, false on failure.

Yac::flush

Immediately invalidates all existing items across all Yac instances. This does not actually free any resources — it only marks all items as invalid. The operation is global and affects the entire shared memory pool, regardless of which instance (or prefix) calls it.

Yac::info

Get cache info and statistics.

Each field means:

Memory management

Yac maintains two independent pools:

What to watch

The core metric is the hit rate: hits / (hits + miss). The counters accumulate from start_time, so compute it over the deltas between two info() snapshots to reflect the current window instead of the lifetime average.

Yac::dump

Dump cache entries for debugging. Returns an array of entries, each containing:

Note: Before 2.4.0, dump() did not report atime, hits, embedded or c_len — these fields do not exist in older versions — and v_len was the stored (compressed) length rather than the original value length.

Small values are embedded in the slot itself instead of allocating a value block: NULL, booleans, small integers, strings up to 7 bytes and empty arrays. Embedded entries allocate no value memory at all, so for them crc and size are reported as 0, while atime and hits are kept in the slot and remain meaningful.

$limit controls the maximum number of entries returned (default 100). Passing -1 dumps all entries — intended for debugging only: the whole result is materialized as a PHP array and can consume a lot of memory on a busy cache.

$offset (since Yac 2.4.0) skips the first $offset occupied entries, so dump($limit, $offset) returns entries $offset + 1 through $offset + $limit. If fewer than $offset entries exist (including an empty cache), an empty array is returned.

Note: Since delete() only marks entries expired (see Yac::delete) and dump() is a raw scan of all occupied slots, deleted or expired entries may still show up in the output. To filter them out, check the ttl field: ttl == 0 means never expires; a non-zero ttl that is less than the current time indicates an expired or deleted entry.

c_len makes it easy to see how much compression saves per entry:

Implementation Notes

License

PHP-3.01


All versions of yac with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 laruence/yac contains the following files

Loading the files please wait ...