Download the PHP package iqbalmalik89/guzzle-application-cache-subscriber without Composer

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

DEPRECATED ⛔

This repository has been deprecated as of 2019-01-27. That code was written a long time ago and has been unmaintained for several years. Thus, repository will now be archived. If you are interested in taking over ownership, feel free to contact me.


guzzle-application-cache-subscriber

Build Status

Plugin for Guzzle 5 to cache requests/responses on an application level scope. This is different from the CacheSubscriber because it doesn't adhere to HTTP caching standards but leaves it to the developer to decide what to cache and when to request a fresh response. Although I shamelessly used the CacheStorage from said plugin :)

Description

This plugin works as a transparent proxy for requests made to the same URL using the same HTTP verb. I use it frequently when developing API wrappers to avoid making multiple calls to the same API endpoint. This is particularly helpful in cases where the API usage is restricted to a certain amount of requests.

The underlying cache library is Doctrine/Cache and I like to use the FilesystemCache to store responses on disk and have it available on the next test run.

Basic Usage

Output

Making 1. request:
* Hostname was NOT found in DNS cache
*   Trying 93.184.216.119...
* Connected to www.example.com (93.184.216.119) port 80 (#0)
> GET / HTTP/1.1
Host: www.example.com
User-Agent: Guzzle/5.0.3 curl/7.36.0 PHP/5.5.11

< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Cache-Control: max-age=604800
< Content-Type: text/html
< Date: Thu, 13 Nov 2014 09:54:15 GMT
< Etag: "359670651"
< Expires: Thu, 20 Nov 2014 09:54:15 GMT
< Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
* Server ECS (iad/182A) is not blacklisted
< Server: ECS (iad/182A)
< X-Cache: HIT
< x-ec-custom-error: 1
< Content-Length: 1270
< 
* Connection #0 to host www.example.com left intact
Status code of 1. request: 200
Making 2. request:
Status code of 2. request: 200
Making 3. request:
Status code of 3. request: 200
Making 4. request:
Status code of 4. request: 200
Making 5. request:
Status code of 5. request: 200

Notice how only the first request produced a debug outbut. The remaining requests have been fetched from the cache and were intercepted in the before event.

Examples

See examples folder.

Requirements

Installation

The recommended way to install guzzle-application-cache-subscriber is through Composer.

curl -sS https://getcomposer.org/installer | php

Next, update your project's composer.json file to include GuzzleApplicationCacheSubscriber:

{
    "repositories": [ { "type": "composer", "url": "http://packages.myseosolution.de/"} ],
    "minimum-stability": "dev",
    "require": {
         "paslandau/guzzle-application-cache-subscriber": "dev-master"
    }
    "config": {
        "secure-http": false
    }
}

Caution: You need to explicitly set "secure-http": false in order to access http://packages.myseosolution.de/ as repository. This change is required because composer changed the default setting for secure-http to true at the end of february 2016.

After installing, you need to require Composer's autoloader:

General workflow and customization options

The guzzle-application-cache-subscriber uses a closures (canCacheRequest) that is evaluated in the end event to decide wether a request/response can be stored in the cache. If it returns true and the response is not null, it is stored in the cache.

On a subsequent call to the same URL using the same HTTP verb, another closure (mustRequestFresh) is used in the before event to determine if the request can be answered from cache or not. If it returns true and the corresponding response has been cached before, the configuration key has_cached_response (ApplicationCacheSubscriber::CACHED_RESPONSE_KEY) is set to true so that this info might be evaluated later on. On false, the cached response is deleted and Guzzle proceeds to perform the request as usual.

Setting up the validation closures

Output

Request 0
Caching the request/response.
The response came not from cache

Request 1
Trying to serve the response from cache.
The response came from cache

Request 2
Making a fresh request.
Not allowed to cache the request/response.
The response came not from cache

Request 3
Trying to serve the response from cache.
The response came not from cache

Request 4
Trying to serve the response from cache.
The response came from cache

Similar plugins

Frequently searched questions


All versions of guzzle-application-cache-subscriber with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5
guzzlehttp/guzzle Version ^5.3.0
doctrine/cache Version ^1.3.1
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 iqbalmalik89/guzzle-application-cache-subscriber contains the following files

Loading the files please wait ....