php8.5
Home/ Manual/ yac / yac/ Yac::__construct

Yac::__construct

PHP function Edit on GitHub ✎

(PECL yac >= 1.0.0)

Constructor

Description

Yac::__construct(string $prefix = "")

Creates a new Yac instance. The optional prefix is prepended to every key this instance stores, which lets several applications or caches on the same machine use overlapping key names without colliding.

Parameters

prefix

A key prefix, up to 48 bytes (YAC_MAX_KEY_LEN).

Errors/Exceptions

Throws an Exception if the cache is disabled (yac.enable=0), or if prefix is longer than 48 bytes.

Examples

Yac::__construct example

php
<?php
$yac = new Yac();
$yac->set("foo", "bar");

$other = new Yac("app2_");
var_dump($other->get("foo"));    // bool(false): different namespace
$other->set("foo", "baz");       // stored as "app2_foo"
?>

See Also

  • Yac::set
  • Yac::get

Source: reference/yac/yac/construct.xml · from the official PHP manual (php/doc-en)