In this chapter, we will understand the concepts of performance and caching in Grav.
The term performance refers to the system performance in such a way that whether it can handle higher load on system and modify the system to handle a higher load.
Consider the following points relating to the performance of Grav −
To have better performance of Grav, you can use PHP opcache and usercache. The opcache works well with PHP 5.4 and usercache works faster with PHP 5.5, PHP 5.6 and Zend opcache.
The SSD (Solid State Drive) which uses flash memory and has no moving parts. Sometimes cache will be stored in user cache or stored as files. So SSD drives can give better performance.
Virtual machines are the best way of hosting providers under the cloud computing technology. You can specify the resources without interacting with physical equipment. Native hosting is faster than virtual machine. Grav runs better on virtual machines, but for optimal performance you can make use of the native hosting option.
Grav has faster memory in which its cache uses heavy memory that provides better performance on your server. Compared to other platforms, it uses less amount of memory.
Grav uses shared hosting on the shared server to share the things. Sharing hosting is available in a low cost and sometimes it may lead to slow the things on the server.
Multi core processors are used for handling multiple tasks faster. The advanced processors are better than these processors which helps the user to accomplish the task.
In general, cache is a stored data in a cache memory. Cache mechanism makes Grav faster in which browser can get files from cache rather than the original server, saving time and additional network traffic.
Grav uses Doctrine Cache library which supports the following −
Auto (Default) − It uses default option automatically.
File − It specifies cache files present in the cache/ folder.
By default, Grav uses the auto setting. It will try for APC, then for WinCache, XCache and lastly it uses File.
There are 5 types of caching −
YAML configuration caching into PHP.
Core Grav caching for page objects.
Twig caching of template files as PHP classes.
Image caching for media resources.
Asset caching of CSS and jQuery with pipelining.
The caching of YAML configuration stored in the /cache folder. The image caching stores its images in the /images folder. The configuration option for core Grav caching is stored in user/config/system.yml file as shown below −
cache: enabled: true check: method: file driver: auto prefix: 'g'
The enabled option enables the caching by setting it to true.
The method option checks for the updates in pages such as files or folder.
The driver option specifies different types of caching options such as Auto, File, APC, XCache, Memcache, Redis or WinCache.
The prefix option defines cache prefix string.
If you are using the memcached server, then you need to add some extra configuration options by using the memcache driver in the user/config/system.yml file. These options can be defined under the cache: group.
cache: ... ... memcache: server:localhost port: 8080
If you are using redis, then you need to add some extra configuration options by using redis driver in the user/config/system.yml file. These options can be defined under the cache: group.
cache: ... ... redis: server:localhost port: 8080
The Twig template uses its own caching mechanism by using twig driver in the user/config/system.yml file.
twig: cache: true debug: true auto_reload: true autoescape: false
It has some options such as −
cache option enables the twig caching by setting it to true.
debug option enables the twig debug.
auto_reload option is used to reload the changes by setting it to true.
autoescape option is used to auto escape the twig variables.
Events can be used when caching is enabled. This can be enabled for all events except for OnPageContentRaw, OnPageProcessed, OnPageContentProcessed, OnTwigPageVariables and OnFolderProcessed events. These events can be used on all pages and folders and can run only when the events are processing. These events cannot be run after the page has been cached.