Download the PHP package eg-mohamed/laravel-http-client-cache without Composer

On this page you can find all versions of the php package eg-mohamed/laravel-http-client-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 laravel-http-client-cache

Laravel HTTP Client Cache

Latest Version on Packagist Total Downloads Code Style Code Style PHP Version Require License

Opt-in response caching for Laravel's HTTP client. Cache outbound API responses with a single fluent call — without replacing the Http facade or touching Laravel core.

The cache layer wraps the normal PendingRequest, so everything you already use keeps working: Http::fake(), headers, query params, JSON payloads, retries, throwing, and the full Response API (body(), json(), status(), header(), successful(), …).

Installation

The service provider is auto-discovered. Publish the config file if you want to tweak defaults:

Basic usage

Pass a cache key and a TTL (in seconds) to Http::cache(), then chain any normal HTTP client method:

By default only successful GET requests are cached. The first request hits the network; matching requests within the TTL are served from cache without sending another request.

Flexible TTL (stale-while-revalidate)

Pass an array [$fresh, $stale] to use Laravel's Cache::flexible(). Values are served fresh for $fresh seconds, then served stale (and refreshed in the background) up to $stale:

A plain integer, DateInterval, or DateTimeInterface uses normal Cache::remember() behavior.

Caching read-only POST APIs

Some APIs expose read-only data over POST (reports, search, GraphQL). Opt those methods in explicitly — string, array, and enum values are all accepted and normalized to uppercase:

Non-allowed methods simply bypass the cache and perform a normal request.

Checking fromCache()

Every response carries a fromCache() flag:

Cache store

Route the cached payload to a specific store:

Tags

Tags are applied only when the underlying store supports them (e.g. Redis). With a store that does not support tagging, tags are silently ignored instead of throwing:

Conditional caching

Decide per-response whether the result should be cached:

Status-based caching

Limit caching to specific status codes:

Disabling cache

Skip the cache for a single request with dontCache():

Or disable the package globally via config (enabled => false) — every request passes straight through to the network.

Full fluent API

Method Purpose
cache($key, $ttl = null, $methods = null) Start a cached request.
cacheStore(?string $store) Choose the cache store.
cacheTags(array\|string $tags) Tag entries (tag-capable stores only).
cacheKeyPrefix(?string $prefix) Override the cache key prefix.
cacheWhen(Closure $callback) Cache only when the callback returns true.
cacheStatuses(array\|int\|null $statuses) Cache only these status codes.
cacheMethods(array\|string\|UnitEnum $methods) Override cacheable methods.
dontCache() Bypass the cache for this request.
fromCache() (on the response) Whether the response was served from cache.

Configuration

IDE autocompletion

Http::cache() and $response->fromCache() are registered as macros, so editors don't autocomplete them out of the box. This package ships an ide-helper.php stub at its root that PhpStorm indexes automatically from vendor/ — completion for Http::cache(...), Factory/PendingRequest chaining, and Response::fromCache() works with no setup.

If you use barryvdh/laravel-ide-helper, the macros are registered at boot and picked up automatically when you regenerate the helper:

Testing notes

Http::cache() wraps the real pending request, so Http::fake() keeps working. In tests, use the array cache store and remember that a cache hit does not send another request:

Behavior summary

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-http-client-cache with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0||^13.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 eg-mohamed/laravel-http-client-cache contains the following files

Loading the files please wait ...