NAME
PDK::Utils::Cache - A simple cache implementation
VERSION
Version 1.0
SYNOPSIS
use PDK::Utils::Cache;
my $cache = PDK::Utils::Cache->new();
# Set a cache value
$cache->set('user', 'name', 'Alice');
# Get a cache value
my $name = $cache->get('user', 'name');
# Clear a specific cache entry
$cache->clear('user', 'name');
# Clear the entire cache
$cache->clear();
ATTRIBUTES
cache
Type: HashRef[Ref]
Description: A hash reference used to store cache data.
METHODS
get(@keys)
Retrieves a value from the cache.
Parameters:
@keys
- One or more keys representing the path in the cache.
Return value:
The found value or undef
(if not found).
set(@keys, $value)
Sets a value in the cache.
Parameters:
@keys
- One or more keys representing the path in the cache.$value
- The value to be stored.
Throws:
An exception if insufficient parameters are provided.
clear(@keys)
Clears the entire cache or a specific key.
Parameters:
@keys
- (Optional) The specific path to clear.
Note:
If no keys are provided, the entire cache is cleared.
locate(@keys)
Locates a specific node in the cache.
Parameters:
@keys
- A sequence of keys representing the path in the cache.
Return value:
The found reference or undef
(if the path doesn't exist).
AUTHOR
WENWU YAN <968828@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2024 WENWU YAN. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.