Download the PHP package kai-init/laravel-normcache without Composer

On this page you can find all versions of the php package kai-init/laravel-normcache. 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-normcache

Laravel Normcache

Normalized caching for Laravel Eloquent. Self-invalidating, Redis-backed.

Tests Latest Version on Packagist

Most caching packages store each query result as one serialized collection. Normcache takes a different approach: a query cache only stores the matching IDs, while each model's attributes live in their own key. The same model can appear in many cached queries but is only stored once, so a single version bump invalidates everything that returned it, in O(1).

Requirements: PHP 8.2+, Laravel 11/12/13, Redis 4.0+

Table of Contents


Installation

Add the Cacheable trait to any model you want cached:


Usage

Basic Queries

Bypassing the Cache

Cross-Table Queries

Queries that span multiple tables are not cached by default — Normcache can't infer which model writes should invalidate them. dependsOn() lets you declare the dependency explicitly:

All dependsOn queries are cached as versioned raw rows. When any declared model class is written, the versioned key becomes unreachable and the next read re-populates from the database. Pessimistic locks always bypass the cache.

List every table the query reads. An under-declared dependency means silent staleness until TTL. Use tag() / flushTag() when you need manual invalidation for events the model version system cannot see.

Per-Query TTL

Aggregates

withCount, withSum, withAvg, withMin, withMax, and withExists are cached automatically and invalidated when related rows change.

Relationship Caching

BelongsTo, BelongsToMany, MorphTo, MorphToMany, MorphedByMany, HasManyThrough, and HasOneThrough are cached for eager loads — on a warm hit no SQL is executed. HasOne, HasMany, MorphOne, and MorphMany are cached via the query cache when the related model uses Cacheable.

attach, detach, sync, and updateExistingPivot automatically invalidate the relevant pivot cache.

Manual Flush

If you mutate cacheable tables outside Eloquent, flush manually after the write:

Tag-Based Flush

Tag any query to group cache entries for manual flushing — useful for invalidation events the version system can't see (deploys, config changes, nightly rebuilds):

Post::on('replica') is not supported. Use distinct model classes with a fixed $connection for per-connection cache isolation.


Cache Bypasses

Query feature Workaround
Pessimistic locking (lockForUpdate / sharedLock) None — must hit DB
Inside a database transaction None — must hit DB
Raw SQL / DB::table(...) None — flush manually

Everything else — JOIN, GROUP BY, DISTINCT, subquery WHERE, raw ORDER BY, calculated columns — is cacheable with dependsOn().


Limitations


Configuration

cooldown — Consecutive writes within the window bump the version only once. Useful for write-heavy models.

fallback — When true, Redis exceptions are caught, the cache is disabled for the request, and queries fall back to the database.

events — Set to false to disable hit/miss event dispatches on hot paths.

fire_retrieved — When true, models hydrated from Redis fire Eloquent's retrieved event (disabled by default).


Observability

Laravel Debugbar

When fruitcake/laravel-debugbar is installed, enable the Normcache collector:

This adds a Normcache timeline tab showing every query hit, miss, bypass, and model fetch — with key, kind, and duration — for the current request.

Events

Event Fired when Properties
QueryCacheHit Cached query result served from Redis modelClass, key
QueryCacheMiss Query not cached — DB queried modelClass, key
ModelCacheHit Model attributes served from Redis modelClass, ids[]
ModelCacheMiss Model attributes not cached — DB queried modelClass, ids[]

Redis Clustering

Every key uses a hash tag derived from the model class — {posts}, {analytics:posts} — so all keys for a given model land on the same cluster slot. MGET batches, Lua scripts, and pipelines never cross node boundaries.

Enable with 'cluster' => true in the config. flushAll() is supported.


Octane & Horizon

Works out of the box. State is reset between Octane requests and queue jobs — including re-enabling the cache if a Redis error disabled it mid-job.


Performance


License

MIT


All versions of laravel-normcache with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
laravel/framework Version ^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 kai-init/laravel-normcache contains the following files

Loading the files please wait ...