开发者

Symfony filter to run before and possibly skip the controller

The idea of the desired filter is to check the memcached for page content with url as a key and if found, return it to client directly from cache and skip the controller altogether. Storing would be done in separate filter, which is the easy part. I'm aware i could write it to action's preExecute() but filters would offer more elegant solution (could turn them off for dev envs).

In other words - is there a smart way for a filter to push the response to clie开发者_开发问答nt and skip going to action?


Implementing such a filter is quite easy. Actually similar solution exists in symfony.

Look at the default caching filter (sfCacheFilter class). It's doing something similar to what you're looking for.

Alternative path

It is already possible to use memcache directly by changing the default file caching to memcache.

In your factories file you're able to switch cache driver (apps/yourapp/config/factories.yml or config/factories.yml):

all:
  view_cache:
    class: sfMemcacheCache

You could do the same with memcached but as symfony doesn't provide sfMemcachedCache class you would have to implement it on your own.

This way you could reuse existing caching framework and take advantage of cache.yml files.


I would suggest you have a look at overwriting the sfExecutionFilter.

It's the last filter in the default filters.yml, which means it's the first executed. This is what is responsible for calling your action's executeXXX method and loading associated view and bunch of other things.

Presumably you could write your own filter the extends sfExecutionFilter and overwrite it's functionality to skip executing the controller it the output is cached.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜