2017 © Pedro Peláez
 

library cacheable-rendering

image

oprokidnev/cacheable-rendering

  • Tuesday, October 17, 2017
  • by oprokidnev
  • Repository
  • 1 Watchers
  • 1 Stars
  • 271 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 24 % Grown

The README.md

Cacheable placeholder module

Provides a set of utils for html caching including placeholder view helper calls interception and restore., (*1)

Installation

composer require oprokidnev/cacheable-rendering:^2.0

Initialize module 'Oprokidnev\\CacheableRendering' in application.config.php and run you application once. Then you will get a new file in config/autoload named cacheable-rendering.config.local.php. This is the config with storage settings. By default I choose use filesystem cache adapter, but you can change this settings with the compatible with \Zend\Cache\StorageFactory::factory method array., (*2)

View helpers

CachedCallback

This is the most typical example when you should use callback cache., (*3)

cachedCallback($key, function ($cacheTags) use ($serviceFromController) { ?>
    <?php foreach($veryBigIteratorWithLazyLoading->getItems() as $item): ?>
        <div class="item"><?= $item->getName()?></div>
    <?php endforeach; ?>
    <?php $this->placeholder('modals')->captureStart(); // placeholder call happens here ?>
    <div class="modal">
        <!-- Some modal body, that will be restored on cache read -->
    </div>
    <?php $this->placeholder('modals')->captureEnd(); ?>
    <?php
    $cacheTags[] = 'database_cache';
    return 'Some finish message';
}); ?>

CachedPartial

The same as standart partial helper, instead of $key parameter in invocation., (*4)


echo $this->cachedPartial($someKey, $locationOrViewModal, $varsOrNothing);

CachedCapture

Encapsulates expensive output action inside while code block. Good for the cases, when cachedCallback closure will require big amount of scope variables., (*5)

<?php while ($this->cachedCapture($key  = 'capture', $tags = ['default'])): ?>
    <?php sleep(1); ?>
    some havy output action here.
<?php endwhile; ?>

Interacting with cache storages

The Versions

17/10 2017
19/04 2017

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/oprokidnev/CacheableRendering

  Sources   Download

The Requires

 

zf2 zendframework optimization placeholder rendering cacheing