-
Notifications
You must be signed in to change notification settings - Fork 82
Caching
Caching is a very important part of this module. Without caching, you're going to have a bad time. Filtering assets, looking them up and then optionally creating a collection can be resource intensive. Without caching, your response times will go down and with mild popularity so will your webserver.
This page assumes that you've taken a look at the quick start, and that you're already serving a basic asset.
## Caching assets Specifying to which assets the caching types apply is done with the `key` for the array entry. There's a `default` key, which is the `default` and there's an option to add specific assets, being the `exception`.
<?php
return array(
'asset_manager' => array(
'caching' => array(
'default' => array(
'cache' => 'CachingType', // Apc, FilePath, FileSystem etc.
),
'css/exception.css' => array(
'cache' => 'CachingType', // Apc, FilePath, FileSystem etc.
),
),
),
);AssetManager also suplies another caching method to store files the way you retrieved them. I will be covering all caching types.
APC is a well known opcode cache. I will therefor not explain in detail what it does. If you do wish to find out what it does, I recommend taking a look at the documentation.
To enable the APC cache, simply add the following to your config:
<?php
return array(
'asset_manager' => array(
'caching' => array(
'default' => array(
'cache' => 'Apc',
),
),
),
);And that's it! the first request will perform all required actions on your assets, and the second request will serve it from APC. The default key specifies that this should be applied to all assets. If you wanted to specify this for a very specific asset, or asset collection, you'd do this:
<?php
return array(
'asset_manager' => array(
'caching' => array(
'test-asset.css' => array(
'cache' => 'Apc',
),
),
),
);By simply changing the key. You could also combine them, and cache everything through APC and a specific asset through something else:
<?php
return array(
'asset_manager' => array(
'caching' => array(
'default' => array(
'cache' => 'Apc',
),
'test-asset.css' => array(
'cache' => 'Filesystem',
'options' => array(
'dir' => 'public', // path/to/cache
),
),
),
),
);<?php
return array(
'asset_manager' => array(
'caching' => array(
'test-asset.css' => array(
'cache' => 'Filesystem',
'options' => array(
'dir' => 'public', // path/to/cache
),
),
),
),
);Example:
<?php
return array(
'asset_manager' => array(
'caching' => array(
'test-asset.css' => array(
'cache' => 'FilePath',
'options' => array(
'dir' => 'public', // path/to/cache
),
),
),
),
);