2017 © Pedro Peláez
 

library content-cache

A simple package - caching content on server before response to clients, support Slim Framework PHP.

image

lovecoding/content-cache

A simple package - caching content on server before response to clients, support Slim Framework PHP.

  • Friday, June 29, 2018
  • by thanglt
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

LoveCoding\ContentCache

ContentCache is a simple package - for web service made by SLim Framework, that's helps you cache your content on server. One time handle, more times using., (*1)

Installation

It's recommended that you use Composer to install ContentCache., (*2)

$ composer require lovecoding/content-cache

This will install ContentCache and all required dependencies. ContentCache requires PHP 5.3.0 or newer., (*3)

Usage

Create an index.php file with the following contents:, (*4)

Demo using Slim 3.x framework, (*5)

<?php

require 'vendor/autoload.php';

$app = new Slim\App();

$container = $app->getContainer();

$container['cacheService'] = function() {
    // path to folder contains cached
    $cacheProvider = new \LoveCoding\ContentCache\CacheProvider('storage/cache');

    return $cacheProvider;
};

$app->get('/cache/array', function ($request, $response, $args) use($container) {
    $cacheService = $container->get('cacheService');

    // $cacheService->cache return a json
    $contentArrayCache = $cacheService->cacheArray($request, function() {

        // This function will run when $content is null on server
        // TODO something

        // Must return an array
        return ...;
    });

    return $response->withJson(json_encode($contentArrayCache));
});

$app->get('/cache/plaintext', function ($request, $response, $args) use($container) {
    $cacheService = $container->get('cacheService');

    $contentCache = $cacheService->cache($request, function() {
        // This function will run when $content is null on server
        // TODO something

        // return and save something you want on server
        return ...;
    });

    return $response->getBody()->write($contentCache);
});

// Using salt for many content
$app->get('/cache/plaintext', function ($request, $response, $args) use($container) {
    $cacheService = $container->get('cacheService');

    $firstList = $cacheService->salt('salt_for_firstList')->cacheArray($request, function() {
        // This function will run when $content is null on server
        // TODO something

        // return and save something you want on server
        return ...;
    });

    $secondList = $cacheService->salt('salt_for_secondList')->cacheArray($request, function() {
        // This function will run when $content is null on server
        // TODO something

        // return and save something you want on server
        return ...;
    });

    return $response->withJson(json_encode([$firstList, $secondList]));
});

$app->run();

You may quickly test this using the built-in PHP server:, (*6)

$ php -S localhost:8000

Going to http://localhost:8000/cache/array or http://localhost:8000/cache/plaintext will now display your content cached., (*7)

The Versions

29/06 2018

dev-master

9999999-dev

A simple package - caching content on server before response to clients, support Slim Framework PHP.

  Sources   Download

MIT

The Requires

 

by thanglt5

29/06 2018

1.5

1.5.0.0

A simple package - caching content on server before response to clients, support Slim Framework PHP.

  Sources   Download

MIT

The Requires

 

by thanglt5

17/05 2018

1.3

1.3.0.0

A simple package - caching content on server before response to clients, support Slim Framework PHP.

  Sources   Download

The Requires

 

by thanglt5

17/05 2018

1.2

1.2.0.0

A simple package - caching content on server before response to clients, support Slim Framework PHP.

  Sources   Download

The Requires

 

by thanglt5

16/05 2018

1.1

1.1.0.0

Caching content before response to client

  Sources   Download

The Requires

 

by thanglt5