\Omega\Cache\Adapter FileAdapter

File adapter class.

The FileAdapter class implements a cache adapter that stores cached data in files. It extends the AbstractCacheAdapter class and provides methods to read, write, and manage cache data stored in files.

Summary

Methods
Properties
Constants
__construct
has
get
put
forget
flush
config
cached
config
No public constants found
No protected methods found
No protected properties found
No protected constants found
getPath
getBase
read
write
No private properties found
No private constants found

Properties

$cached

$cached : array

Cacheds data.

Type

array<string, mixed> — Holds an array to store cached data.

$config

$config : array

Type

array<string|int, mixed>

Methods

__construct()

__construct(array  $config) : void

AbstractCacheAdapter class constructor.

Parameters

array $config

Holds the configuration options for the cache adapter.

Returns

void —

has()

has(string  $key) : bool

Check if a value exists in the cache.

Parameters

string $key

Holds the cache key to check.

Returns

bool —

Returns true if the key exists in the cache, otherwise false.

get()

get(string  $key, mixed  $default = null) : mixed

Retrieve a cached value by its key.

Parameters

string $key

Holds the cache key to retrieve.

mixed $default

Holds the default value to return if the key is not found.

Returns

mixed —

Return the cached value if found, otherwise the default value.

put()

put(string  $key, mixed  $value, ?int  $seconds = null) : $this

Store a value in the cache with an optional expiration time.

Parameters

string $key

Holds the cache key to store.

mixed $value

Holds the value to store in the cache.

?int $seconds

Holds the number of seconds until the cache item expires (null for no expiration).

Returns

$this —

Return the cache adapter instance.

forget()

forget(string  $key) : $this

Remove a single cache value by its key.

Parameters

string $key

Holds the cache key to remove.

Returns

$this —

Return the cache adapter instance.

flush()

flush() : $this

Remove all cached values.

Returns

$this —

Return the cache adapter instance.

config()

config() : array<string,mixed>

Get the config.

Returns

array

Return an array of config.

getPath()

getPath(string  $key) : string

Get the cache path for a specific key.

Parameters

string $key

Holds the cache key.

Returns

string —

Return the cache path for the specified key.

getBase()

getBase() : string

Get the cache base directory.

Returns

string —

Return the base directory for storing cache files.

read()

read(string  $key) : mixed|array

Read the cache data from a file.

Parameters

string $key

Holds the cache key.

Returns

mixed|array —

Return the cached data, or an empty array if not found.

write()

write(string  $key, mixed  $value) : $this

Write the cache data to a file.

Parameters

string $key

Holds the cache key.

mixed $value

Holds the value to cache.

Returns

$this —

Return the cache adapter instance.