This repository was archived by the owner on Feb 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
7.x 2.x Function: at_cache
Andy Truong edited this page Jan 21, 2014
·
9 revisions
<?php
function your_data_provider($reset = FALSE) {
$cache_id = '…';
$bin = 'bin';
$expire = strtotime('+ 15 minutes');
if (!$reset && $cache = cache_get($cache_id, $bin)) {
return $cache->data;
}
$data = your_logic();
cache_set($data, $cache_id, $bin, $expire);
return $data;
}
$output = your_data_provider();Our logic becomes cleaner:
<?php
function your_data_provider() {
return your_logic();
}
$options = array('id' => '…', 'bin' => 'cache', 'ttl' => '+ 15 minutes', 'reset' => FALSE);
$output = at_cache($options, 'your_data_provider');
// Faster
$output = at_cache('cache_id', 'your_data_provider'); ___ ___________ _ _
/ _ \_ _| ___ \ | | | |
/ /_\ \| | | |_/ / __ _ ___ ___ _ __ ___ ___ __| |_ _| | ___
| _ || | | ___ \/ _` / __|/ _ \ | '_ ` _ \ / _ \ / _` | | | | |/ _ \
| | | || | | |_/ / (_| \__ \ __/_| | | | | | (_) | (_| | |_| | | __/
\_| |_/\_/ \____/ \__,_|___/\___(_)_| |_| |_|\___/ \__,_|\__,_|_|\___|
- Caching
- Twig template
- twig Service
- twig_string Service
- Recipes
- Extends
- Easy Block
- Easy Routing
- Easy Breadcrumb
- Entity Template
- Drush Commands:
- Functions:
- Misc
- Status
- Tools for Development enviroment
- /devel/php improved
- /at/sql
- /at/twig
- Kint integration