Download the PHP package eusonlito/laravel-database-cache without Composer

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

Database Query Cache

Requirements

Installation

You can install the package via composer:

Add the Eusonlito\DatabaseCache\CacheBuilderTrait to your model:

Configuration

Add this variables to .env file:

Default configuration values are set in config/database-cache.php file:

Also you can set custom ttl and key on every ->cache(:ttl, :key) call.

Usage

Just use the cache() method to remember a Query result before the execution. That's it. The method automatically remembers the result for 3600 seconds.

If you are using the default config, this cache will be stored inside ['database', 'database|articles'] tags.

The next time you call the same query, the result will be retrieved from the cache instead of running the SQL statement in the database, even if the result is null or false.

The cache() will throw an error if you build a query instead of executing it.

Time-to-live

By default, queries are remembered by 60 seconds, but you're free to use any length, Datetime, DateInterval or Carbon instance.

Custom Cache Key

The auto-generated cache key is an BASE64-MD5 hash of the SQL query and its bindings, which avoids any collision with other queries while keeping the cache key short.

If you are using the default config, this cache will be stored inside ['database', 'database|articles'] tags with the key latest_articles.

Operations are NOT commutative

Altering the Builder methods order will change the auto-generated cache key hash. Even if they are visually the same, the order of statements makes the hash completely different.

For example, given two similar queries in different parts of the application, these both will not share the same cached result:

To ensure you're hitting the same cache on similar queries, use a custom cache key. With this, all queries using the same key will share the same cached result:

This will allow you to even retrieve the data outside the query, by just asking directly to the cache.

Remember that you need to pass the same ordered list of tags to the tags method as when cache was stored. Always use ['database', 'database|XXX'] when XXX is the table name related with the query.

Tags

This package tag caches with two different tags (only supported by redis and memcached)

Flush caches

You can flush all database caches or only caches related with only one table:

License

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


All versions of laravel-database-cache with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/database Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/support Version ^8.0|^9.0|^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 eusonlito/laravel-database-cache contains the following files

Loading the files please wait ....