Download the PHP package xmadmax/xcache without Composer

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

XCache

XCache allows to cache everything, html, json, views, objects, results from a Class->method, also can put a Cache-Control headers to be used for CDN's or proxies. v.3.0.5007

Three methods allowed:

XCache comes with this drivers:

New: Added XCACHE_BASEID to allow separated cache on same source code

Install

Composer

Edit your base composer.json, and add:

Update composer:

Now, you can include XCache with composer autoload in any of your php files:

Configuration

XCache drivers

File

Configure xcacheconf.json with:

In the cache_host group, define the absolute path to the 'cache' directory to be created:

In Windows, the path is relative to the drive where the php program is located. The compress option is available, takes more time to compress, but less time reading and less space on disk.

Memcache
Configure xcacheconf.json with:

And, in the cache_hosts group:

Define host as "host:port". The compress is available, takes more time to compress, but less time reading and less space on shared memory. If php_memcache is not avaliable, then file driver is used.

Memcached

Configure xcacheconf.json with:

And, in the cache_hosts group:

Define hosts as "host:port", or "host:port,host:port,host:port" for a group of servers. The OPT_PREFIX will compose the key of any item saved in the collection, allowing to xcache/memcached to be used with other apps at same time. The compress option is available, takes more time to compress, but less time reading and less space on shared memory. If php_memcached is not avaliable, then file driver is used.

MongoDB

Configure xcacheconf.json with:

And, in the cache_hosts group:

Define hosts as "host:port:user:passwd:database:collection". The OPT_PREFIX will compose the key of any item saved in the collection, allowing to xcache/mongodb to be used with other apps at same time. The compress option is available, takes more time to compress, but less time reading and less space on ram/disk. If php_mongodb is not avaliable, then file driver is used.

Redis

Configure xcacheconf.json with:

And, in the cache_hosts group:

Define host as "host:port". The OPT_PREFIX will compose the key of any item saved in the collection, allowing to xcache/redis to be used with other apps at same time. The compress option is available, takes more time to compress, but less time reading and less space on ram/disk. If php_redis is not avaliable, then file driver is used.

Apc
Configure xcacheconf.json with:

And, in the cache_hosts group:

The compress is available, takes more time to compress, but less time reading and less space on shared memory. If php_apc is not avaliable, then file driver is used.

Other options

Cache even when $_GET is set

If you want to cache neither when is recieved GET parameters (example: http://www.myweb.com?param=111), cache_get must to set to 'true' Even when a page is called with GET paremeters, they will be part of the uniqueID to compose de cache key, allowing to have a diferent cache if GET parameters change.

Cache even when $_POST is set

If you want to cache neither when is recieved POST parameters, cache_post must to set to 'true' Even when a page is called with POST paremeters, they will be part of the uniqueID to compose de cache key, allowing to have a diferent cache if POST parameters change.

Cache only when a user is not logged

If you want to cache ONLY when no user is logged, your app must to write a cookie in the browser. The cookie name can be configured in 'cache_logged_cookie' option. When XCache detect this cookie, and 'cache_only_not_logged_pages' is set to 'true', the cache is deactivated.

XCache usage & examples

XCache can cache :

Automatic cache for any method

If you have a class like this:

Modifiy as described:

Now, you can call:

The XCacheDriver will not find 'myMethod' in 'myClass', but will find '_myMethod'. Then will look in xcacheconf.json, in the 'cache_method' group, with the name of 'myClass_myMethod', and will retrieve the TTL for this cache. The xcacheconf.json can look like this:

Then, before the call of $myClass->myMethod($params), XCache will look for a cache for this method&params, if found, will return the value, if not, the method will be called and the value returned will be cached.

You can configure regular expressions to cache a group of methods, for example, to cache all methods in myClass:

Regexp expressions are evaluated with preg_match. You can use any combination that preg_match accepts.

Cache a whole PHP code

You can cache all the output of a block of code, the cacheID will be the REQUEST_URI: If you have a php with bootstrap or any opther code launching the base core class:

Modify the code as described:

The writeAndFlushCache method must to be the last line where the output of the php file ends.

To make it works, you need to configure the 'cache_pages' group in the xcacheconffile.json, to detect the REQUEST_URI. For example, if the bootstrap file is loaded by htaccess as default, it will capture any url, as '/' or '/mypage', then this parameter must to be defined in the xcacheconffile.json:

The 'home' will be cached 1 hour, 'mypage' will be cached 5 minutes, any other page will be cached 30 seconds (default)

Cache an specific method of a class

XCache can work alone or as a trait of any class. To work alone, use the previous example (Cache a whole PHP code), to work as a trait, use the example (Automatic cache for any method) This is usefull if you want to include XCache in any PHP code.

The XCacheDriver have two byPass methods to XCache:

Both can be called inside any class that have the same structure as described in (Automatic cache for any method), for example:

The 'myMethod' is not underscored, but can also be called with 'xcacheMethod':

The result is retrived from cache if it exists, if not, the $myClass->myMethod($params) is called, stored in cache and returned. This allow to have the call and cache retrieving in only one line. As described before, you need to add "myClass_myMethod" to the 'cache_method' group in xcacheconf.json file:

The xCacheMethod takes 6 arguments:

  1. Cache group
  2. Cache name
  3. Unique ID, must to contain also the params values
  4. The object class
  5. The name of the method
  6. The params

Cache a key/value pair

As described before, "xCacheValue" is also available inside any class that inherits the XCacheDriver trait. Using the same example described before:

Use this to save a result value:

To have it working, the "myResult" key, must to be configured in the 'cache_values' group in xcacheconf.json, if not, will take the 'default' TTL: "cache_values": { "default": 15, "regexp": { "^myResult$": 300 } }

To retrieve this result in any other php or line of code:

Set Cache-control headers

XCache can 'only' put a 'Cache-control' HTML headers to be understood by a CDN. Using the same example as for whole page cache, in the index.php or bootsrap.php :

Modify the code as described:

Use of XCache without XCacheDriver

Include the composer autoload in your php file.

Cache an specific method of a class

As described before, you need to add "myClass_myMethod" to the 'cache_method' group in xcacheconf.json file:

Cache a key/value pair

To have it working, the "myResult" key, must to be configured in the 'cache_values' group in xcacheconf.json, if not, will take the 'default' TTL: "cache_values": { "default": 15, "regexp": { "^myResult$": 300 } }

To retrieve this result in any other php or line of code:


All versions of xcache with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.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 xmadmax/xcache contains the following files

Loading the files please wait ....