RosfEsiSimulatorPlugin - 1.0.2

It renders components, partials or any piece of code you need to speed up, the same way as it would be if you were using Edge-Side Includes (ESI).

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source | Show as Markdown

RosfEsiSimulatorPlugin

It renders components, partials or any piece of code you need to speed up, the same way as it would be if you were using Edge-Side Includes (ESI).

Example: Suppose you have a very hard to render component that shows the News. Its content don't need to be refreshed everytime an user access to the site. You can ask the component to refresh every 5 minutes instead of refreshing it every time an user access to the site. If any user access before these 5 minutes, he is going to get the cached version (static html output) of the component instead of rendering it again.

First of all, it's not ESI actually, because it doesn't use the ESI tags, it's just a very simple implementation of the Edge-Side Includes behavior so it's handled by symfony.

It was inspired by the ESI implementation in Symfony2, but i needed it for symfony 1.4 and 1.2. http://docs.symfony-reloaded.org/master/guides/cache/http.html#using-edge-side-includes

INSTALLATION

  • Enable The plugin

  • Add to "standard_helpers" in settings.yml the following helpers:

    • Partial # if it's not enabled already

    • Esisimulator

Using the symfony Standard helpers include_component and include_partial

Now, you'll have to use helpers: include_component_esi and include_partial_esi. If you don't want to use these helpers, and you want to use include_component and include_partial, there is one more step: (This is very nasty by the way)

You can rename PartialHelper.php-dist PartialHelper.php to inside the plugin directory. Sorry for that, but i couldn't find a better way to decorate helpers with symfony

Configuring

Suppose you have this line:

include_component_esi('module1', 'component1');

or

include_component('module1', 'component1'); //if you use PartialHelper.php Included in this plugin

In your app.yml: you have to add

all
  rosfEsiSimulatorPlugin:
    active: true
    cachables:

      * {cachable_id: component_module1_component1, expiration: 180 }

      * {cachable_id: partial_news_list, expiration: 5 }

The "expiration" time is in minutes.

The module1/component1 is going to be rendered if it's been more than 180 minutes since the last rendering.

The result is saved in the %sf_cache_dir%/ResEsiSimulator directory

to include a partial it would be the same:

include_partial_esi('news/list');

or include_partial('news/list'); //if you use PartialHelper.php Included in this plugin In app.yml

* {cachable_id: partial_news_list, expiration: 5 }

Note the "partial_" prefix instead of "component_"

Caching something else than components and partials

$esiSimulator = new ResEsiSimulatorHandler();
$esiSimulator->prepareArbitrary("STRING_ID");
if($esiSimulator->useCached()){
  echo $esiSimulator->render();
}else{
slot('something');
   <?php echo "things you want to cache."; ? >
end_slot();

echo $esiSimulator->saveIfIsConfigured(get_slot('something'));

}

and in application configuration:

all
  rosfEsiSimulatorPlugin:
    active: true
    cachables:

     * {cachable_id: component_module1_component1, expiration: 180 }

     * {cachable_id: partial_news_list, expiration: 5 }

     * {cachable_id: something, expiration: 5 }