Download the PHP package foxws/laravel-modelcache without Composer

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

Laravel model cache helper

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Attach arbitrary cached values to Eloquent model instances or classes using any Laravel cache driver. By default each authenticated user gets an isolated cache namespace, so two users never share the same cached value for the same model.

See the full documentation (or browse Customization.

Installation

Install the package via Composer:

Optionally publish the config file:

Environment variables

Variable Default Description
MODEL_CACHE_ENABLED true Toggle caching on/off globally
MODEL_CACHE_STORE CACHE_STORE Cache store to use (any store from config/cache.php)
MODEL_CACHE_LIFETIME 604800 (1 week) Default TTL in seconds

[!TIP] Let your AI agent do the hard parts. This package ships a Laravel Boost skill, modelcache-development, that teaches your agent how to install, configure and use Laravel Model Cache. Install Boost and select the skill when prompted:

Already using Boost? Run php artisan boost:update --discover to pick up the skill. Then just ask, for example: "Remember each user's playback position on my Video model."

Usage

1. Add the trait to your model

That is all the setup required. Every public method below becomes available on the model.


2. Instance cache

These methods are scoped to a specific model record (e.g. Video with id = 5).

Store a value:

Retrieve a value:

Check existence:

Forget a value:

Remember a value (fetch or store):

modelCacheRemember returns the cached value if it exists, otherwise resolves the closure (or uses the plain value), stores it, and returns it.

Practical example — lazy-load an expensive computed value:


3. Class cache (global)

These static methods are scoped to the model class rather than a specific record. Useful for values shared across all instances, such as global seeds or configuration.

Store a value:

Retrieve a value:

Check existence:

Forget a value:


4. Facade

Use the ModelCache facade when you need to interact with caching outside of a model — for example in an action class or a service.


5. Controlling which values get cached (shouldModelCache)

Override shouldModelCache on the model to conditionally skip caching certain keys or values:


6. Custom cache profile

A cache profile controls global caching behaviour: whether caching is enabled, when values expire, and which per-user namespace suffix to use. The default is CacheAllSuccessful, which caches all values for all users.

Create your own by implementing CacheProfile:

Register it in config/modelcache.php:


7. Per-model cache namespace (cacheNameSuffix)

By default, BaseCacheProfile::useCacheNameSuffix returns the authenticated user's ID, isolating each user's cache. You can override this per model:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

This package is heavily inspired by and based on the spatie/laravel-responsecache package by Spatie.

If you find their work valuable, please consider sponsoring Spatie or purchasing one of their courses and products.

License

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


All versions of laravel-modelcache with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/cache Version ^12.0|^13.0
illuminate/console Version ^12.0|^13.0
illuminate/contracts Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
spatie/laravel-package-tools Version ^1.9
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 foxws/laravel-modelcache contains the following files

Loading the files please wait ...