Download the PHP package germania-kg/cachecallable without Composer

On this page you can find all versions of the php package germania-kg/cachecallable. 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 cachecallable

Germania KG · CacheCallable

Packagist PHP version Tests

Callable convenience wrapper around PSR-6 Cache Item Pools: Seamlessly creates, returns, and stores your data.

Caching business is pretty much always similar and can be outlined like this:

  1. Is caching enabled at all? If not, delete any according older entry first.
    Create and return fresh content anyway, ending up here.
  2. Does a given item exist? If so, return item content;
    Otherwise, create, store and return content.

The CacheCallable class reduces these steps to a handy and customizable Callable.

Installation with Composer

Example

Although this example uses phpfastcache, you should be able to pass in any Cache Item Pool. Use your favourite PSR-3 Logger; this example will use the well-known Monolog.

A word on cache keys

According to the PSR-6 specs, cache keys should be limited to A-Z, a-z, 0-9, _, and . to ensure maximum compatibilty. So if you pass in a PSR-6 Adapter from Symfony Cache component, class CacheCallable internally converts the given keys to a MD5 representation.

In case you'd like to provide a custom cache key creation, you may use the setCacheKeyCreator method whoch accepts any callable:

PHP-FIG: PSR-6: Caching Interface

Implementing libraries MUST support keys consisting of the characters A-Z, a-z, 0-9, _, and . in any order in UTF-8 encoding and a length of up to 64 characters. Implementing libraries MAY support additional characters and encodings or longer lengths, but must support at least that minimum.

Symfony docs: “Cache Item Keys and Values”

The key of a cache item […] should only contain letters (A-Z, a-z), numbers (0-9) and the _ and . symbols.

The Cache lifetime

Think of a webpage that turns out to be not cached during script runtime — after we set up the Cache wrapper. For this reason, the Cache wrapper constructor also accepts a LifeTimeInterface implementation with a getValue method:

The LifeTime class is a simple implementation of this interface. It additionally enables you to change the lifetime value during runtime. Since we passed it to our Cache constructor by reference, the Cache wrapper can decide after content creation wether to cache or not.

Create a Lifetime object

Usage with CacheCallable

Your Logger will now output something like this:

How to change lifetime during script runtime

After instantation, you may use the setValue method:

The LifeTime class is a simple implementation of this interface. It additionally enables you to change the lifetime value during runtime. Since we passed it to our Cache constructor by reference, the Cache wrapper can decide after content creation wether to cache or not.

Create a Lifetime object:

Set time value after instantation

Usage with CacheCallable

Your Logger will now output something like this:

How to override content creation

If you prefer singleton services, you may invoke the CacheCallable with a custom content creator parameter to override the default one:

Issues

The PSR-6 Caching Interface mock in CacheCallableTest could need an overhaul. Discuss on #issue 3

Development

Unit tests

Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:

Useful Links


All versions of cachecallable with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
psr/cache Version ^1.0|^2.0|^3.0
psr/log Version ^1.0|^2.0|^3.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 germania-kg/cachecallable contains the following files

Loading the files please wait ....