Documentation

Cache
in package
implements CacheInterface

Table of Contents

Interfaces

CacheInterface

Constants

GCP_ENV_KEY  = "GOOGLE_CLOUD_PROJECT"

Properties

$client  : SecretManagerServiceClient
$projectId  : string
$projectName  : string

Methods

__construct()  : mixed
Construct a new instance for a specific project
clear()  : bool
Wipes clean the entire cache's keys.
create()  : bool
delete()  : bool
Delete an item from the cache by its unique key.
deleteMultiple()  : bool
Deletes multiple cache items in a single operation.
get()  : mixed
Fetches a value from the project's secrets.
getMultiple()  : array<string, mixed>
Obtains multiple cache items by their unique keys.
has()  : bool
Determines whether an item is present in the cache.
set()  : bool
Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
setMultiple()  : bool
Persists a set of key => value pairs in the cache, with an optional TTL.
serialize()  : string

Constants

GCP_ENV_KEY

public mixed GCP_ENV_KEY = "GOOGLE_CLOUD_PROJECT"

Properties

$client

private SecretManagerServiceClient $client

$projectId

private string $projectId

$projectName

private string $projectName

Methods

__construct()

Construct a new instance for a specific project

public __construct([string $projectId = null ]) : mixed
APIYes
Parameters
$projectId : string = null

Optional. If no project ID is provided, the environment will be checked for the standard GOOGLE_CLOUD_PROJECT variable to be used.

clear()

Wipes clean the entire cache's keys.

public clear() : bool
Return values
bool

True on success and false on failure.

create()

public create(string $key[, mixed $value = null ]) : bool
Parameters
$key : string
$value : mixed = null
Return values
bool

delete()

Delete an item from the cache by its unique key.

public delete(string $key) : bool
Parameters
$key : string

The unique cache key of the item to delete.

Tags
throws
InvalidArgumentException

MUST be thrown if the $key string is not a legal value.

Return values
bool

True if the item was successfully removed. False if there was an error.

deleteMultiple()

Deletes multiple cache items in a single operation.

public deleteMultiple(iterable<string|int, mixed> $keys) : bool
Parameters
$keys : iterable<string|int, mixed>

A list of string-based keys to be deleted.

Tags
throws
InvalidArgumentException

MUST be thrown if $keys is neither an array nor a Traversable, or if any of the $keys are not a legal value.

Return values
bool

True if the items were successfully removed. False if there was an error.

get()

Fetches a value from the project's secrets.

public get(string $key[, mixed $default = null ]) : mixed
Parameters
$key : string

The unique key of this item in the cache.

$default : mixed = null

Default value to return if the key does not exist.

Tags
throws
InvalidArgumentException

MUST be thrown if the $key string is not a legal value.

Return values
mixed

The value of the item from the cache, or $default in case of cache miss.

getMultiple()

Obtains multiple cache items by their unique keys.

public getMultiple(iterable<string|int, mixed> $keys[, mixed $default = null ]) : array<string, mixed>
Parameters
$keys : iterable<string|int, mixed>

A list of keys that can obtained in a single operation.

$default : mixed = null

Default value to return for keys that do not exist.

Tags
throws
InvalidArgumentException

MUST be thrown if $keys is neither an array nor a Traversable, or if any of the $keys are not a legal value.

Return values
array<string, mixed>

A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.

has()

Determines whether an item is present in the cache.

public has(string $key) : bool

NOTE: It is recommended that has() is only to be used for cache warming type purposes and not to be used within your live applications operations for get/set, as this method is subject to a race condition where your has() will return true and immediately after, another script can remove it, making the state of your app out of date.

Parameters
$key : string

The cache item key.

Tags
throws
InvalidArgumentException

MUST be thrown if the $key string is not a legal value.

Return values
bool

set()

Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.

public set(string $key, mixed $value[, null|int|DateInterval $ttl = null ]) : bool
Parameters
$key : string

The key of the item to store.

$value : mixed

The value of the item to store. Must be serializable.

$ttl : null|int|DateInterval = null

Included for PSR-16 compatibility. Numeric values for $ttl will be treated as the number of secret versions to retain. Others will be destroyed.

Tags
throws
InvalidArgumentException

MUST be thrown if the $key string is not a legal value.

Return values
bool

True on success and false on failure.

setMultiple()

Persists a set of key => value pairs in the cache, with an optional TTL.

public setMultiple(iterable<string|int, mixed> $values[, null|int|DateInterval $ttl = null ]) : bool
Parameters
$values : iterable<string|int, mixed>

A list of key => value pairs for a multiple-set operation.

$ttl : null|int|DateInterval = null

Included for PSR-16 compatibility. Non-null arguments will destroy the prior version of the secret.

Tags
throws
InvalidArgumentException

MUST be thrown if $values is neither an array nor a Traversable, or if any of the $values are not a legal value.

Return values
bool

True on success and false on failure.

serialize()

private serialize(mixed $value) : string
Parameters
$value : mixed
Tags
throws
InvalidArgumentException

if the $value neither a string nor JSON serializable

Return values
string

        
On this page

Search results