Download the PHP package genealabs/laravel-model-caching without Composer

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

Model Caching for Laravel

Laravel Package Scrutinizer BCH Compliance Coveralls GitHub (pre-)release Packagist GitHub license

Model Caching for Laravel masthead image

Supporting This Package

This is an MIT-licensed open source project with its ongoing development made possible by the support of the community. If you'd like to support this, and our other packages, please consider becoming a sponsor.

We thank the following sponsors for their generosity, please take a moment to check them out:

Impetus

I created this package in response to a client project that had complex, nested forms with many <select>'s that resulted in over 700 database queries on one page. I needed a package that abstracted the caching process out of the model for me, and one that would let me cache custom queries, as well as cache model relationships. This package is an attempt to address those requirements.

Features

Cache Drivers

This package is best suited for taggable cache drivers:

It will not work with non-taggable drivers:

Requirements

Possible Package Conflicts

Any packages that override newEloquentModel() from the Model class will likely conflict with this package. Of course, any packages that implement their own Querybuilder class effectively circumvent this package, rendering them incompatible.

The following are packages we have identified as conflicting:

Things That Don't Work Currently

The following items currently do no work with this package:

installation guide cover

Installation

Be sure to not require a specific version of this package when requiring it:

Gotchas If Using With Lumen

The following steps need to be figured out by you and implemented in your Lumen app. Googling for ways to do this provided various approaches to this.

  1. Register the package to load in Lumen:

  2. Make sure your Lumen app can load config files.
  3. Publish this package's config file to the location your app loads config files from.

Upgrade Notes

0.6.0

The environment and config variables for disabling this package have changed.

0.5.0

The following implementations have changed (see the respective sections below):

Configuration

Recommended (Optional) Custom Cache Store

If you would like to use a different cache store than the default one used by your Laravel application, you may do so by setting the MODEL_CACHE_STORE environment variable in your .env file to the name of a cache store configured in config/cache.php (you can define any custom cache store based on your specific needs there). For example:

Usage

For best performance a taggable cache provider is recommended (redis, memcached). While this is optional, using a non-taggable cache provider will mean that the entire cache is cleared each time a model is created, saved, updated, or deleted.

For ease of maintenance, I would recommend adding a BaseModel model that uses Cachable, from which all your other models are extended. If you don't want to do that, simply extend your models directly from CachedModel.

Here's an example BaseModel class:

Multiple Database Connections

Thanks to @dtvmedia for suggestion this feature. This is actually a more robust solution than cache-prefixes.

Keeping keys separate for multiple database connections is automatically handled. This is especially important for multi-tenant applications, and of course any application using multiple database connections.

Optional Cache Key Prefix

Thanks to @lucian-dragomir for suggesting this feature! You can use cache key prefixing to keep cache entries separate for multi-tenant applications. For this it is recommended to add the Cachable trait to a base model, then set the cache key prefix config value there.

Here's is an example:

The cache prefix can also be set in the configuration to prefix all cached models across the board:

Exception: User Model

I would not recommend caching the user model, as it is a special case, since it extends Illuminate\Foundation\Auth\User. Overriding that would break functionality. Not only that, but it probably isn't a good idea to cache the user model anyway, since you always want to pull the most up-to-date info on it.

Experimental: Cache Cool-down In Specific Models

In some instances, you may want to add a cache invalidation cool-down period. For example you might have a busy site where comments are submitted at a high rate, and you don't want every comment submission to invalidate the cache. While I don't necessarily recommend this, you might experiment it's effectiveness.

To use it, it must be enabled in the model (or base model if you want to use it on multiple or all models):

After that it can be implemented in queries:

or:

Disabling Caching of Queries

There are two methods by which model-caching can be disabled:

  1. Use ->disableCache() in a query-by-query instance.
  2. Set MODEL_CACHE_ENABLED=false in your .env file.
  3. If you only need to disable the cache for a block of code, or for non- eloquent queries, this is probably the better option:

Recommendation: use option #1 in all your seeder queries to avoid pulling in cached information when reseeding multiple times. You can disable a given query by using disableCache() anywhere in the query chain. For example:

Manual Flushing of Specific Model

You can flush the cache of a specific model using the following artisan command:

This comes in handy when manually making updates to the database. You could also trigger this after making updates to the database from sources outside your Laravel app.

Summary

That's all you need to do. All model queries and relationships are now cached!

In testing this has optimized performance on some pages up to 900%! Most often you should see somewhere around 100% performance increase.

Commitment to Quality

During package development I try as best as possible to embrace good design and development practices, to help ensure that this package is as good as it can be. My checklist for package development includes:

Contributing

Please observe and respect all aspects of the included Code of Conduct https://github.com/GeneaLabs/laravel-model-caching/blob/master/CODE_OF_CONDUCT.md.

Reporting Issues

When reporting issues, please fill out the included template as completely as possible. Incomplete issues may be ignored or closed if there is not enough information included to be actionable.

Submitting Pull Requests

Please review the Contribution Guidelines https://github.com/GeneaLabs/laravel-model-caching/blob/master/CONTRIBUTING.md. Only PRs that meet all criterium will be accepted.

If you ❤️ open-source software, give the repos you use a ⭐️.

We have included the awesome symfony/thanks composer package as a dev dependency. Let your OS package maintainers know you appreciate them by starring the packages you use. Simply run composer thanks after installing this package. (And not to worry, since it's a dev-dependency it won't be installed in your live environment.)


All versions of laravel-model-caching with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
genealabs/laravel-pivot-events Version ^10.0|^11.0
illuminate/cache Version ^10.0|^11.0
illuminate/config Version ^10.0|^11.0
illuminate/console Version ^10.0|^11.0
illuminate/container Version ^10.0|^11.0
illuminate/database Version ^10.0|^11.0
illuminate/http Version ^10.0|^11.0
illuminate/support Version ^10.0|^11.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 genealabs/laravel-model-caching contains the following files

Loading the files please wait ....