Download the PHP package juhara/zzzcache without Composer

On this page you can find all versions of the php package juhara/zzzcache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package zzzcache

About ZzzCache

A minimalist and simple PHP cache library implementation. Visit Documentation for more information.

Requirement

Installation

Run through composer

$ composer require juhara/zzzcache

How to use

Implement Cacheable interface

Any class that can be stored in cache manager needs to implements Juhara\ZzzCache\Contracts\Cacheable interface, which is data() and ttl() method.

When reading data from cache, cache manager relies on cache storage interface implementation to provide proper serialization/unserialization when read or write data.

There is one Juhara\ZzzCache\Contracts\Cacheable implementation provided, Juhara\ZzzCache\Helpers\ClosureCacheable class, which implements data as closure.

$ttl = 60 * 60 * 1; //cache item for 1 hour
$cacheableItem = new Juhara\ZzzCache\Helpers\ClosureCacheable(function () {
    return [
        'dummyData' => 'dummy data'
    ];
}, $ttl);

When $cacheableItem->data() is called, it calls closure function pass in constructor and return data that defined in closure.

Juhara\ZzzCache\Helpers\ClosureCacheableFactory class implements Juhara\ZzzCache\Contracts\CacheableFactoryInterface and acts as factory for Juhara\ZzzCache\Helpers\ClosureCacheable class.

Of course, you are free to implement your own.

Initialize Cache instance

Juhara\ZzzCache\Cache class is default Juhara\ZzzCache\Contracts\CacheInterface implementation provided with this library.

To use it, you need to provide Juhara\ZzzCache\Contracts\CacheStorageInterface and Juhara\ZzzCache\Contracts\ExpiryCalculatorInterface implementation.

See Storage Implementation for available CacheStorageInterface implementation.

There is Juhara\ZzzCache\Helpers\ExpiryCalculator class which is default ExpiryCalculatorInterface implementation for this library. See Example

<?php

use Juhara\ZzzCache\Cache;
use Juhara\ZzzCache\Storages\File;
use Juhara\ZzzCache\Helpers\ExpiryCalculator;
use Juhara\ZzzCache\Helpers\Md5Hash;

// create a file-based cache where all cache
// files is stored in directory name
// app/storages/cache with
// filename prefixed with string 'cache'
$cache = new Cache(
    new File(
        new Md5Hash(),
        'app/storages/cache/',
        'cache'
    ),
    new ExpiryCalculator()
);

Storage Implementation

Caches need to be stored somewhere. ZzzCache does not implement storage interface. It delegates this to separate library to provide storage implementation, so developer can use storage implementation that suits their needs only. Currently supported implementation is file-based and Redis-based storage.

File-based Storage

To install, run composer

$ composer require juhara/zzzfile

See zzzfile.

Redis-based Storage

To install, run composer

$ composer require juhara/zzzredis

See zzzredis.

Example

Using file as cache storage with zzzfile.

<?php

use Juhara\ZzzCache\Cache;
use Juhara\ZzzCache\Storages\File;
use Juhara\ZzzCache\Helpers\ExpiryCalculator;
use Juhara\ZzzCache\Helpers\Md5Hash;

// create a file-based cache where all cache
// files is stored in directory name
// app/storages/cache with
// filename prefixed with string 'cache'
$cache = new Cache(
    new File(
        new Md5Hash(),
        'app/storages/cache/',
        'cache'
    ),
    new ExpiryCalculator()
);

Using Redis as cache storage with zzzredis.

<?php

use Juhara\ZzzCache\Cache;
use Juhara\ZzzCache\Storages\Redis;
use Juhara\ZzzCache\Helpers\ExpiryCalculator;

// create a redis-based cache
$cache = new Cache(
    new Redis(new \Predis\Client()),
    new ExpiryCalculator()
);

To get data from cache if available or from slower storage.

<?php

...

try {
    //try to get data from cache if available
    $cachedData = $cache->get('itemNeedToBeCache');        
} catch (\Juhara\ZzzCache\Exceptions\CacheNameNotFound $e) {
    $acacheableItem = new \Juhara\ZzzCache\Helpers\ClosureCacheable(
        function () {
            //get data from slower storage
            return ['dummyData'=>'dummyData'];
        },
        60 * 60 * 1 //cache item for 1 hour
    );
    $cachedData = $cache->add('itemNeedToBeCache', $acacheableItem)
                        ->get('itemNeedToBeCache');
}

PSR-16 CacheInterface support

ZzzCache adds support to PSR-16 CacheInterface thorough Juhara\ZzzCache\Psr\AdapterCache class which acts as an adapter. It implements Psr\SimpleCache\CacheInterface. For example,

Contributing

Just create PR if you want to improve it.

Thank you.


All versions of zzzcache with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
psr/cache Version ^1.0
psr/simple-cache Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package juhara/zzzcache contains the following files

Loading the files please wait ....