Download the PHP package italystrap/cache without Composer

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

ItalyStrap Cache API

Build status Latest Stable Version Total Downloads Latest Unstable Version License PHP from Packagist Mutation testing badge

PSR-16 & PSR-6 Cache implementations for WordPress transient and cache the OOP way

Version 2.0 is a BC breaks please read the following documentation

Table Of Contents

Installation

The best way to use this package is through Composer:

This package adheres to the SemVer specification and will be fully backward compatible between minor versions.

For more information about the WordPress API:

Why this package?

Initially I created this package to use the PSR-16 cache interface in WordPress, but starting from this issue #4 I decided to extract the drivers and also add the PSR-6 cache interface too.

From version 2.0 I also added the PSR-6 implementation, so you can also use the Pool class to cache your data if you need it.

So this package now support both the PSR-16 and PSR-6 cache interfaces.

The driver required by this package uses the Transients and Object Cache APIs from WordPress to store the data, but if you need to use other APIs, you can create your own driver because just implements the interface \ItalyStrap\Storage\CacheInterface from Storage API.

Moving from Version 1 to Version 2

The first important thing is from the version 2 you need to pass the driver object and the expiration object to the constructor of the class you want to use.

SimpleCache and Pool are the two classes that need the driver and the expiration to be passed to the constructor.

The driver is an object wrapper for the WordPress Transient API and the WordPress Object Cache API.

The expiration object is used to set the expiration time of the cache.

Below in the documentation you will find the name of the drivers that you can use and the expiration object.

The second important thing is that the driver must implement the CacheInterface from Cache API, this way if you need to create your own driver you can do it simply by implementing the interface.

Why the needs of an Expiration object?

The expiration object is used to set the expiration time of the cache.

Because I want to be as close as possible to the PSR-16 and PSR-6 specifications, I have created an object that is responsible for setting the expiration time, this way I can reuse the same logic across all PSR-16 and PSR-6 implementations and I didn't need to create more methods that are not in the specifications.

Basic Usage

Timer constants

Inside WordPress there are some constants that can be used to express time in seconds. Here is a list of them:

Or you can use the built-in constant from ItalyStrap\Cache\ExpirationInterface:

Or you can use the built-in PHP function strtotime() to express time in seconds.

Common usage with builtin WordPress Transients API

The data you can save can be anything that is supported by the Serialization API. In short, you can save any scalar value, array, object.

Common usage with the Pool cache

Common usage with the SimpleCache

Only if you need to parse binary data (as for example image files) you can use the BinaryCacheDecorator class, but remember that if the file is more than 1MB it is better to not use this to save in the database.

And because you are a good developer, you will not save binary data in the database, and you will use the Transient class instead of the BinaryCacheDecorator class.

Deleting cache with Pool

Deleting cache with SimpleCache

Check cache exists with Pool

Check cache exists with SimpleCache

Saving multiple cache with SimpleCache

Fetching multiple cache with SimpleCache

Deleting multiple cache with SimpleCache

Clearing cache with SimpleCache

This method do not clear the entire WordPress cache, only the cache used by client with ::set() and ::setMultiple() methods.

Cache::clear() will flush 'special_data_to_save', 'key' and 'key2'.

Other examples

You could also use a Bridge to use the \Psr\SimpleCache\CacheInterface and inject the \Psr\Cache\CacheItemPoolInterface

Use the Factory to simplify the creation of the Cache

Contributing

All feedback / bug reports / pull requests are welcome.

License

Copyright (c) 2019 Enea Overclokk, ItalyStrap

This code is licensed under the MIT.

Credits


All versions of cache with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
italystrap/storage Version ^1.0
psr/simple-cache Version ^1.0
psr/cache Version ^1.0
fig/cache-util Version ^1.0
psr/clock 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 italystrap/cache contains the following files

Loading the files please wait ....