Download the PHP package silentbyte/litecache without Composer

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

LiteCache 2.1

Build Status Latest Stable Version MIT License

This is the official repository of the SilentByte LiteCache Library.

LiteCache is a lightweight, easy-to-use, and PSR-16 compliant caching library for PHP 7.0+ that tries to utilize PHP's built in caching mechanisms. Advanced caching systems such as Memcached are often not available on low-cost hosting providers. However, code/opcode caching is normally enabled to speed up execution. LiteCache leverages this functionality by generating *.php files for cached objects which are then optimized and cached by the execution environment.

Installation

The easiest way to install the latest version of LiteCache is using Composer:

More information can be found on Packagist.

If you would like to check out and include the source directly without using Composer, simply clone this repository:

General Usage

LiteCache implements PSR-16 and thus provides a standardized API for storing and retrieving data. The full API documentation is available here: LiteCache 2.0 API Documentation.

Caching 101

Let's get started with the following basic example that demonstrates how to load and cache an application's configuration from a JSON file.

The methods $cache->get($key, $default = null) and $cache->set($key, $value, $ttl = null) are used to retrieve and save the configuration from and to the cache under the unique name config, respecting the defined TTL. In case of a cache miss, the data will be loaded from the actual JSON file and is then immediately cached.

Without the cache as an intermediary layer, the JSON file would have to be loaded and parsed upon every request. LiteCache avoids this issue by utilizing PHP's code caching mechanisms.

The library is designed to cache data of any kind, including integers, floats, strings, booleans, arrays, and objects. In addition, LiteCache provides the ability to cache files and content from the output buffer to provide faster access.

Advanced Caching

The main function for storing and retrieving objects to and from the cache is the method $cache->cache($name, $producer, $ttl). The first parameter $name is the unique name of the object to be stored. $producer is a generator function that will be called if the object has expired or not yet been cached. The return value of this callable will be stored in the cache. $ttl, or time-to-live, defines the number of seconds before the objects expires. If $ttl is not specified, the cache's default time-to-live will be used (in the listed code below, that is 10 minutes).

The following example issues a Github API request using cURL and caches the result for 10 minutes. When the code is run for the first time, it will fetch the data from the Github server. Subsequent calls to the script will access the cached value without issuing a time-expensive request.

Further examples can be found in the ./examples/ directory within this repository.

Using Producers

LiteCache's cache($key, $producer, $ttl) method uses producers (implemented as function objects) that yield the data for storage in the cache. A couple of useful producers are already shipped with LiteCache, namely: FileProducer, IniProducer, JsonProducer, and OutputProducer.

Using the IniProducer with the following *.ini file...

...and this code...

...will result in the configuration file being cached for all further calls of the script, thus avoiding unnecessary parsing on every request. The same concept applies to the other types or producers.

The same concept can be applied to cache PHP's output, e.g. caching a web page in order to avoid having to re-render it upon every request. The easiest way to achieve this is by using the integrated OutputProducer:

All output from the included PHP script (e.g. generated via echo) will be cached for 30 seconds. If you are using a templating engine such as Twig, OutputProducer can be used to cache the rendered page. In case the data is directly available as a string, a simple call to $cache->set($key, $value) will suffice.

See the ./examples/ folder for more details.

Options

LiteCache's constructor accepts an array that specifies user-defined options.

Option Type Description
directory string Location (path) indicating where the cache files are to be stored.
subdivision bool Places cache files into different sub-directories to avoid having many files in the same directory.
pool string Defines the name of the cache pool. A pool is a logical separation of cache objects. Cache objects in different pools are independent of each other and may thus share the same unique name. See PSR-6 #pool.
ttl null
int
string
DateInterval
Time-To-Live. Defines a time interval that signaling when cache objects expire by default. This value may be specified as an integer indicating seconds (e.g. 10), a time interval string (e.g '10 seconds'), an instance of DateInterval, or LiteCache::EXPIRE_NEVER / LiteCache::EXPIRE_IMMEDIATELY.
logger LoggerInterface
null
An instance of a PSR-3 compliant logger class (implementing \Psr\Log\LoggerInterface) that is used to receive logging information. May be null if not required.

Contributing

See CONTRIBUTING.md.

Change Log

See CHANGELOG.md.

FAQ

Under what license is LiteCache released?

MIT license. Check out https://opensource.org/licenses/MIT

How do I permanently cache static files, i.e. configuration files?

Setting the $ttl value to LiteCache::EXPIRE_NEVER will cause objects to remain in the cache until the cache file is deleted manually, either by physically deleting the file or by calling $cache->delete($key) or $cache->clean().


All versions of litecache with dependencies

PHP Build Version
Package Version
Requires psr/simple-cache Version ^1.0
psr/log 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 silentbyte/litecache contains the following files

Loading the files please wait ....