Download the PHP package hkp22/cache-laraview-fragments without Composer

On this page you can find all versions of the php package hkp22/cache-laraview-fragments. 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 cache-laraview-fragments

Cache Laraview Fragments

Laravel view fragment caching support.

Installation

Composer

Download package into the project using Composer.

Registering Service Provider

Laravel 5.5 (or higher) uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

For Laravel 5.4 or earlier releases version include the service provider within app/config/app.php:

Cache Driver

This package has used Laravel tags (like Cache::tags('foo')) to store cache. So, you must use the Laravel cache driver which supports tagging, such as Memcached and Redis.

Make sure required CACHE_DRIVER is used in .env file.

Usage

After package installation, you may use @cache Blade directive in your views.

In production environment, this will cache the HTML fragment "forever." For local development, on the other hand, it will automatically flush the relevant cache for you each time you refresh the page.

Clear Cache

Now because your production server will cache the fragments forever, You should add a step to deployment process that clears the relevant cache.

Caching Models

Consider the following example:

In this above example, $post object is passed to the @cache directive rather than a string. It will look for a getCacheKey() method on the model and this method is defined in Hkp22\CacheLaraViewFragments\Cacheable trait. So, use this trait in the model.

The cache key for model will include the object's id and updated_at timestamp: App\Post/1-1537459253.

Note: Because updated_at timestamp used into the cache key, So whenever post is updated, the cache key will change.

Touching

Consider the following example: resources/views/posts/_post.blade.php

resources/views/posts/_comment.blade.php

In this above example whenever a new comment is created or existing comment is updated. It will not change the view HTML because view HTML is fetched from cache. 

To fix this need to add $touches to the child model (Comment model in this case). So, whenever a new comment is created or updated, it would update the parent's updated_at timestamp.

So, in this case Comment model should like this:

Here the $touches = ['post'] instructs Laravel to update the post relationship's timestamps each time the comment is updated.

Caching Collections

You may also cache the collection.


All versions of cache-laraview-fragments with dependencies

PHP Build Version
Package Version
Requires php Version ^5.6|^7.0
illuminate/support Version ^5.1
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 hkp22/cache-laraview-fragments contains the following files

Loading the files please wait ....