Symfony filter to run before and possibly skip a controller

The idea of ​​the filter you need is to check memcached content for a page with url as a key, and if it is found, return it to the client directly from the cache and generally skip the controller. Storage will be carried out in a separate filter, which is the easy part. I know that I can write it in the preExecute () action, but the filters would offer a more elegant solution (could disable them for dev envs).

In other words - is there a way for the filter to send a response to the client and skip the action?

+3
source share
2 answers

I would advise you to take a look at rewriting sfExecutionFilter.

This is the last filter in default filters.yml, which means that it is first executed. This is what is responsible for calling the actionXXX method and loading the view associated with it and a bunch of other things.

Presumably you can write your own filter, extend sfExecutionFilter and overwrite it to skip the execution of the controller to which it is cached.

You can find the default filters .yml @% SYMFONY_DIR% / config / config / filters.yml

0
source

The implementation of such a filter is quite simple. In fact, a similar solution exists in symfony.

Look at the default caching filter (sfCacheFilter class). He does something similar to what you are looking for.

Alternative way

memcache, memcache.

(apps/yourapp/config/factoryories.yml config/factories.yml):

all:
  view_cache:
    class: sfMemcacheCache

memcached, symfony sfMemcachedCache, .

cache.yml.

+2

Source: https://habr.com/ru/post/1781691/


All Articles