Download the PHP package langsys/laravel-request-query-cache without Composer

On this page you can find all versions of the php package langsys/laravel-request-query-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-request-query-cache

Laravel Request Query Cache

A request caching toolkit for Laravel with two independent features:

  1. Per-request query deduplicationfirstCached() / getCached() macros that run a query once per request and serve identical repeats from an in-memory store flushed when the request ends. (Not a persistent cache.)
  2. Idempotent HTTP responses — an idempotent middleware that replays the stored response for a repeated Idempotency-Key instead of executing the route again. (Persistent: uses your configured cache store.)

The two share nothing but the package — pick either, or both. Query dedup needs no config; idempotency is opt-in per route.

Why would I want this?

The single best use case is a query you run to validate input that you then need again downstream.

Validation rules and controllers naturally re-express the same query. A rule fetches a row to check it exists / is in the right state; then the controller (or service) fetches that same row to actually do the work. That's two identical round trips to the database for one logical lookup.

The usual workarounds are awkward: smuggle the already-fetched model out of the rule into the controller, or skip the rule and re-validate inline in the controller. With firstCached()/getCached() you don't have to. Both layers just write the natural query — identical SQL + bindings hit the database once, and the controller gets the row the rule already loaded.

The goal: zero validation in the controller/service layer — validation stays in the rule where it belongs, and the controller reuses the query for free.

Example: a custom rule and a controller sharing one query

A vanilla Laravel validation rule that runs a query:

The controller validates, then reuses the exact same query — no second DB hit, no model smuggled out of the rule, no inline re-validation:

The rule has already done the DB work; the controller's query resolves from the in-memory store. The only requirement is that both queries are identical — same where/whereNull clauses in the same order, so they produce the same SQL and bindings.

Installation

The service provider is auto-discovered. No configuration required.

Usage

If the same query (identical SQL and bindings) runs again during the same request, it returns the stored result without touching the database.

Different queries are cached independently — bindings are part of the cache key, so where('id', 1) and where('id', 2) never collide.

How it works

Caveat: writes within the same request

Because results are memoized on SQL + bindings, if you write to a row and then re-query it with firstCached()/getCached() in the same request, you get the pre-write cached value. Use the uncached first()/get() after a write you need to read back in-request.

Idempotent HTTP responses

State-changing endpoints (payments, orders, sign-ups) get retried — by impatient users, flaky networks, and queue workers. The idempotent middleware makes those retries safe: the client sends a unique Idempotency-Key header, and any repeat of that key replays the original response instead of running the route twice.

How a request is handled

  1. Only POST/PUT/PATCH are guarded (configurable). Everything else passes through.
  2. No key present → 400 if the route requires it, otherwise passes through.
  3. Key seen before, same request → the stored response is replayed.
  4. Key seen before, different request body → 422 (the key was reused for something else — a client bug you want surfaced, not silently mishandled).
  5. Key currently in flight (a concurrent duplicate) → 409 + Retry-After: 1. An atomic lock guarantees the route body runs at most once even under a simultaneous double-submit.

A request's identity (its fingerprint) is the HTTP method + route + path parameters + query string + body. Body field order doesn't matter — {"a":1,"b":2} and {"b":2,"a":1} are the same request. Reusing one key across different path parameters (e.g. /projects/A vs /projects/B) is treated as misuse and returns 422. The key is namespaced by scope so two callers can use the same key without colliding.

Scopesuser | ip | global | apikey:

Per-route overrides

Override ttl, required, and scope inline — idempotent:{ttl},{required},{scope}:

Configuration

Defaults work out of the box. To customize, publish the config:

TTL guidance: default to 24h for money/order endpoints (a retry hours later must not double-charge — same window Stripe uses); drop to minutes for cheap, high-volume endpoints.

Requirements & caveats

The middleware also exposes $request->attributes->get('idempotent') (bool) and 'idempotency-key' to downstream code.

Note: attribute-style usage (#[Idempotent] on a controller method) is not wired up yet — use the idempotent middleware alias or class for now.

Testing

License

MIT


All versions of laravel-request-query-cache with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.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 langsys/laravel-request-query-cache contains the following files

Loading the files please wait ...