承接 qimnet/update-tracker-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

qimnet/update-tracker-bundle

Composer 安装命令:

composer require qimnet/update-tracker-bundle

包简介

QIMNET Update tracker bundle

关键字:

README 文档

README

This bundle is used to track updates on entites and cache results client side or server side according to the update times.

Configuration

An UpdateTracker entity has to be added to the project to use the bundle.

The following code can be used :

<?php
namespace ACME\MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;

use Qimnet\UpdateTrackerBundle\Entity\UpdateTracker as BaseUpdateTracker;

/**
 * @ORM\Entity
 */
class UpdateTracker extends BaseUpdateTracker
{

}

The name of the entity should then be added to your config.yml file :

qimnet_update_tracker:
    entity_name: 'ACME\MyBundle\Entity\UpdateTracker'

Tracking entity changes

To track the changes of a given entity, you have two choices :

  • use the Qimnet\UpdateTrackerBundle\Annotation\TrackUpdate annotation on your entity class
  • implement Qimnet\UpdateTrackerBundle\UpdateTracker\TrackUpdateInterface in your entity class

The changes can then be tracked using the qimnet.update_tracker.manager service.

Using HTTP cache validation

To generate HTTP responses and use HTTP cache validation, use the qimnet.update_tracker.http_cached_response_factory service :

<?php
namespace ACME\MyBundle\Controller;
class MyController
{
    public function myAction() 
    {
        $response = $this->get('qimnet.update_tracker.http_cached_response_factory')
            ->generate('my_namespace');
        if ($response->isNotModified($this->getRequest())) {
            return $response;
        }
        // Fetch content
        $response->setContent('Some content');
        return $response;
    }
}

Using timestamps in Urls

Timestamped URL are useful for using HTTP cache expire headers with dynamic content. This can be useful for :

  • content which can afford to have a changing URL
  • ESI

To use timestamped URLs in your twig templates, use the timestamped_path, timestamped_url and timestamped_controller functions.

Here is an example of this type of caching strategy with an ESI :

namespace ACME\MyBundle\Controller;
class MyController
{
    /**
    *   Every variation of the output of this method should update the 
    *  "my_update_tracker" UpdateTracker.
    * 
    *   @Cache(expires="+1year")
    **/
    public function esiAction() {
        ...
        return $response;
    }
}
    {# /ACME/MyBundle/Resources/views/layout.html.twig #}
    ...
    {% render_esi(timestamped_url("acme_mybundle_mycontroller_esi", {}, "my_update_tracker")) %}
    ...

Using server side caching

To use server side caching, enable the cache manager in your configuration file :

qimnet_update_tracker:
    cache_manager:

        # True to enable the cache manager.
        enabled:              true

You can then request cached object using the qimnet.update_tracker.cache_manager service :

<?php
namespace ACME\MyBundle\Controller;
use Symfony\Component\HttpFoundation\Response;

class MyController
{
    public function myAction($id)
    {
        $content = $this->get('qimnet.update_tracker.cache_manager')
            ->getObject('my_namespace', 'my_object/' . $id, function(){
                //Fetch the content and return it
                return 'Some content';
            })
        return new Response($content);
    }
}

You can also render cached fragments directly from yout templates by using the render tag with the cache strategy :

{{ render(controller("MyBundle:MyController:myAction"), { strategy: "cache", "updateTrackerName": "my_update_tracker", ttl: 120 }) }}

Cache entries are automatically deleted when the corresponding update tracker namespace is changed.

统计信息

  • 总下载量: 31
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-03-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固