Symfony

Original author: Symfony
  • Transfer
Love this framework.
I will translate part of the information as it is read. I think that it will not be useful to me alone. In turn, I propose to discuss and complement all those who care about this topic and framework

Chapter 12 - Caching


One way to speed up the operation of a web-based application is to memorize part or all of the HTML document for re-issuing it at the following requests. This technology is known as caching. It can be used both on the server side and on the client side.

Symfony offers a flexible server-side caching system. Allows you to save full server responses, the result of any action, or a fragment of the template to a file described in accordance with the YAML format (http://www.yaml.org/). When the data is updated, you can clear part of the cache through the command line or special methods (note I assume here we are talking about methods that are specially reserved for these purposes in ramework). Symfony also offers an easy way for client-side caching using HTTP 1.1. (http://www.w3.org/Protocols/)This chapter will reveal the caching capabilities mentioned above, provide hints for practical use in your applications.

Response Caching

The principle of HTML caching is simple: part or all of the HTML code that is sent in response to a user’s request can be used repeatedly for similar requests. HTML code for this purpose is stored in a special place ( cache / folder ). Before processing the request from the client to the server, the controller first of all tries to view this particular folder for data availability. If the cached data is found, then it will be sent without performing any additional actions on the server side (approx. Static), thereby significantly reducing the load on the processor time of the server. But if the data is not found, then the handler of the triggered event will work, will form the data for the response and write it to the cache / folder . In the future, the entire operation is repeated.

By default, the cache is off. To use it, you must have administrator rights for the site. (?)

Symfony supports three types of caching:
1. Event cache
2. Partial component cache
3. Template fragment cache

The first two types of caching are managed using YAML files. Caching template fragments is controlled by auxiliary (?) Functions of the template.

Global cache settings

For each application in the project (in the context of Symfony), the HTML caching mechanism can be applied or not (the cache is disabled by default) by specifying settings in the settings.yml environment

Here is an example demonstrating the activation of the caching mechanism:
frontend / config / settings.yml
dev:
[tab] .settings:
[tab] [tab] cache: [tab] [tab] [tab] [tab] on


[approx. learn the syntax of YAML]

Event caching

Events that display static information (exclude dynamically generated data from the database and depending on sessions) or actions to read unchanging information from the database (usually GET requests) are ideal for caching. In a visual form (image 12-1) it is shown which page elements are cached depending on the case: the result of the action (this is a template) or the action of the result together with the format.

Images 12-1 - Event Caching
Event caching

For an example, consider user / listAn event that returns all site users. If there is no modification, deletion or addition () change with user data, and this information is often displayed on the site, then this is the case when you should think about caching.

Enabling and configuring the cache for events is defined in cache.yml , which is located in the config module directory / See Listing 12-2 for an example

Listing 12-2
list:
[tab] enabled: [tab] on
[tab] with_layout: [tab] false [tab] # Default value
[tab] lifetime: [tab] 86400 [tab] # Default value


to be continued…

Also popular now: