From 5679b86a8bc875bca2d41e4b3d298dc90eef0b99 Mon Sep 17 00:00:00 2001 From: Jeffrey Way Date: Tue, 23 Feb 2016 17:27:41 -0500 Subject: [PATCH] Update docs to reflect caching collections --- readme.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/readme.md b/readme.md index ec68a22..32bb3f0 100644 --- a/readme.md +++ b/readme.md @@ -157,6 +157,22 @@ Now, everything is in place. You might render your view, like so: Notice the Russian-Doll style cascading for our caches; that's the key. If any note is updated, its individual cache will clear - along with its parent - but any siblings will remain untouched. +### Caching Collections + +You won't always want to cache model instances; you may wish to cache a Laravel collection as well! No problem. + +```html +@cache($posts) + @foreach ($posts as $post) + @include ('post') + @endforeach +@endcache +``` + +Now, as long as the `$posts` collection contents does not change, that `@foreach` section will never run. Instead, as always, we'll pull from the cache. + +Behind the scenes, this package will detect that you've passed a Laravel collection to the `cache` directive, and will subsequently generate a unique cache key for the collection. + ## FAQ **1. Is there any way to override the cache key for a model instance?**