Skip to content

Releases: silmar-alberti/PhpCache

1.1.1

14 Feb 21:34
2b4c1d3
Compare
Choose a tag to compare
Merge pull request #9 from silmar-alberti/dev

version 1.1.1

1.1.0

21 Nov 18:31
Compare
Choose a tag to compare

Added increase function

1.0.2

19 Sep 21:46
e7da047
Compare
Choose a tag to compare

change fail return on get cache by false to null

1.0.1

09 Aug 15:53
Compare
Choose a tag to compare

solved error on RedisAdapte where get function returned false instead of null

1.0.0

08 Aug 00:41
Compare
Choose a tag to compare

Initial version

PhpCache

extensible and flexible php cache lib.

Install to project

composer require silmaralberti/php-cache

Docs

Use example

// set redis adapter connection
$redisConnectionParams = [
    'host' => 'host.docker.internal'
];

$serializer = new IgBinaryLib();
$redisAdapter = new RedisAdapter($redisConnectionParams);
$hash = new HashKeyLib();

$testSettings = new PhpCacheSettingsModel(
    $redisAdapter,
    $serializer,
    $hash
);

$phpCache = new PhpCache($testSettings);
$queryContent = [
    'keyA' => 'keyContentA',
    'keyB' => 'keyContentB'
];

$valueContent = [
    'valueA' => 'contentA',
    'valueB' => 'contentB'
];
$successOnSave = $phpCache->set($queryContent, $valueContent);
// $successOnSave true if success else false

$cachedValueContent = $phpCache->get($queryContent);
// false if not found in cache 
// $cachedValueContent is equal $valueContent

Serializer Classes

  • IgBinaryLib
  • DefaultSerializerLib

Adapter Class

  • RedisAdapter

KeyGenerator Lib

  • HashKeyLib

PhpCache Methods

get()

load cache data

set()

storage cache data

cacheFunction()

get response of function from cache or call function and store result on cache

example:

$serializer = new IgBinaryLib();
$redisAdapter = new RedisAdapter($redisConnectionParams);
$hash = new HashKeyLib();

$testSettings = new PhpCacheSettingsModel(
    $redisAdapter,
    $serializer,
    $hash
);

$phpCache = new PhpCache($testSettings);

$testValue = 'storedOnCacheValue';

$result = $phpCache->cacheFunction(
    function ($testValue) {
        return $testValue;
    },
    [$testValue],
    'functionExample'
);

echo $result;
// print 'storedOnCacheValue';