-
Notifications
You must be signed in to change notification settings - Fork 1
/
nitro.start.php
67 lines (62 loc) · 2.04 KB
/
nitro.start.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
********************************
* !!! IMPORTANT !!! *
*DO NOT USE ON NEW INTEGRATIONS*
* THIS FILE IS DEPRECATED *
* BACKWARDS COMPATIBILITY ONLY *
********************************
*/
// Load NitroPack libraries
require_once dirname(__FILE__) . "/vendor/autoload.php";
// Initialize NitroPack with your site ID and secret
$nitro = new NitroPack\SDK\NitroPack('your_site_id', 'your_site_secret');
// Check any administrative URLs that should clear the cache
// Purge all cache
// $purgeCacheUrls = array(
// 'GET' => array('/purge'),
// 'POST' => array(),
// 'PUT' => array(),
// 'HEAD' => array(),
// 'DELETE' => array()
// );
// if (in_array($_SERVER['REQUEST_URI'], $purgeCacheUrls[$_SERVER['REQUEST_METHOD']])) {
// $nitro->purgeCache();
// $nitro->fetchConfig();
// }
// // End of purge snippet
// Purge cache for a specific tag only so your pages get optimized faster
// $clearPageCacheUrls = array(
// 'GET' => array('/clearpagecache'),
// 'POST' => array(),
// 'PUT' => array(),
// 'HEAD' => array(),
// 'DELETE' => array()
// );
// if (in_array($_SERVER['REQUEST_URI'], $clearPageCacheUrls[$_SERVER['REQUEST_METHOD']])) {
// $nitro->purgeCache(null, 'mainpages');
// $nitro->fetchConfig();
// }
// End of tag purge snippet
$layout = 'default';
// Use different layouts for different types of pages (product page, category page, etc)
// $layoutStartingWith = array(
// '/product/' => 'productlayout',
// '/category/' => 'categorylayout'
// );
// foreach ($layoutStartingWith as $startingWith => $useLayout) {
// if (substr($_SERVER['REQUEST_URI'], 0, strlen($startingWith)) == $startingWith) {
// $layout = $useLayout;
// }
// }
// Serve cache if available
if ($nitro->hasCache($layout)) {
$nitro->pageCache->readfile();
exit;
}
// Tag your pages so you can clear parts of your cache separately, which results in faster optimization
// else {
// if ($nitro->isAllowedUrl()) {
// $nitro->tagUrl($nitro->getUrl(), 'mainpages');
// }
// }