Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/trapvincenzo/static-view-cache
Static View Cache for Laravel4 (Blade template engine)
https://github.com/trapvincenzo/static-view-cache
Last synced: about 1 month ago
JSON representation
Static View Cache for Laravel4 (Blade template engine)
- Host: GitHub
- URL: https://github.com/trapvincenzo/static-view-cache
- Owner: trapvincenzo
- Created: 2014-12-16T11:23:16.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-19T15:04:33.000Z (over 9 years ago)
- Last Synced: 2024-10-01T16:53:21.634Z (about 2 months ago)
- Language: PHP
- Homepage:
- Size: 183 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#Static View Cache for Laravel4 (Blade template engine)
Suppose to include a view (with dynamic data) inside another view:
```php
@include('cardetail', ['car' => $car])
```
For this statement, the blade engine creates a cached file for the subview like this:
```php
make('car', $car, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>;
```
This means that for every request of the page, the rendering code is executed.
##Loop
The problem comes when the inclusion is made inside a loop. Executing the code at every iteration, can cause a big delay in the rendering of the page.
##Cached subview
What the StaticViewCache does, is to save a cached version of the generated subview with the real data. Doing so, the code for the rendering will be executed just the first time (to create the cache).
##How to use
To install the StaticViewCache as a Composer package, add this line to your composer.json:
```php
"trapvincenzo/static-view-cache": "dev-master"
```
and update your vendor folder running the ```composer update ``` command.
Register the service provider (app/config/app.php):
```php
'providers' => array(
...
'Trapvincenzo\StaticViewCache\StaticViewCacheServiceProvider'
...
)
```
Replace the @include statement with:
```php
StaticViewCache::render($viewName, $id, $data , $path )
```
string **$viewName** view name
string **$id** unique identifier for the view (different for each iteration)
array **$data** data to use inside the view
[optional] string **$path** define path inside storage_folder().'/views/' (default 'static')
Enjoy!