Download the PHP package harmonyio/cache without Composer

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

Cache

Latest Stable Version Build Status Build status Coverage Status License

Async caching library

Requirements

In addition for non-blocking context one of the following event libraries should be installed:

Installation

Usage

This library both provides interfaces for working with the cache from external libraries as well as providing a way to interface with the cache directly.

This is mostly intended to be used by cache aware libraries and should in most cases not be worked with directly as this is a low-level library.

Complete example usage

Working with the cache

Cache interface

The cache provides 4 methods to interface with:

Cacheable items

To build an item to be stored in the cache create an instance of \HarmonyIO\Cache\Item.php:

The above example will create an item to be cached (in this case a fake response from an http call) and stores it in the cache for 60 seconds.

TTL

There are three main ways to define the TTL for items to be cached.

By defining the expiration time:

Ttl::fromDateTime expects an instance of \DateTimeInterface

By defining the TTL in seconds:

By defining the TTL in seconds using one of the provided common used TTL values as constants:

Key

The key cacheable items use consists of three parts:

Type

The type refers to the type of the resource that is being stored. Common use cases are for example: HttpRequest or DatabaseQuery.

The type is used as a way of grouping cached items in the cache and to provide a way to easily purge antire groups of items from the cache.

Source

The type refers to the identifier of the resource itself. For http requests this would commonly be the URL. Or for database queries this would be the query.

The source is used as a way of grouping cached items in the cache and to provide a way to easily purge entire groups of items from the cache.

Hash

The hash must be a unique identifier for one specific cacheable item in the cache. For example for a database query an hash created from both the prepared statement as well as the bound parameters:

The following pseudo-code illustrates what a valid hash could be:

Providers

Currently two caching providers are implemented as part of this library: Redis and InMemory.

Redis provider

The recommended provider to use is the redis cache provider: \HarmonyIO\Cache\Provider\Redis. To set up the Redis provider inject the Redis client with the correct Redis address:

InMemory (array) provider

This library also provides an in-memory (simple php array) provider: \HarmonyIO\Cache\Provider\InMemory. This is more meant for development purposes and should probably not be used in production.
To set up the InMemory:

\HarmonyIO\Cache\CacheableRequest and \HarmonyIO\Cache\CacheableResponse interfaces

This library provides two interfaces to be used in external cache aware libraries:

\HarmonyIO\Cache\CacheableRequest

Any cacheable actions / resources that can be done in a cacheable aware library should accept an instance of \HarmonyIO\Cache\CacheableRequest:

This interface enforces cacheable requests to have both a key and a TTL.

An example of a cacheable request can be found at the HttpClient package: https://github.com/HarmonyIO/Http-Client/blob/56db13437e388b178c2d0b926f16a906aa48f9ae/src/Message/CachingRequest.php

Both the request as well as the eventual response will result in an cacheable item which can be stored in the cache.

\HarmonyIO\Cache\CacheableResponse

Any cacheable actions / resources that can be done in a cacheable aware library should result in an instance of \HarmonyIO\Cache\CacheableResponse:

This makes sure responses from the cacheable actions / resources can be safely stored in cache.

Both the request as well as the eventual response will result in an cacheable item which can be stored in the cache.


All versions of cache with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3
amphp/amp Version ^2.1.1
amphp/cache Version ^1.2
amphp/redis Version ^0.3.3
amphp/uri Version ^0.1.3
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 harmonyio/cache contains the following files

Loading the files please wait ....