Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Etag and expiration cache utility
PHP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src/PlasmaConduit
.gitignore
README.md
composer.json
composer.lock

README.md

Http Cache

An Etag and expiration based cache utility library.

<?php
use PlasmaConduit\HttpCache;

$content = "hello world\n";
$etag    = HttpCache::digest($content);

if (HttpCache::isEtagHit($etag)) {
    HttpCache::finalizeHit();
} else {
    HttpCache::setEtagDirectly($etag);
    HttpCache::finalizeMiss();
    echo $content;
}

Public Interface

namespace PlasmaConduit;

class HttpCache {

    const CONTROL_PUBLIC   = "public";
    const CONTROL_PRIVATE  = "private";
    const CONTROL_NO_CACHE = "no-cache";
    const CONTROL_NO_STORE = "no-store";

    /**
     * Just a simple sha1 wrapper, subject to change
     *
     * @param {String} $content - The content to digest
     * @return {String}         - The digested signature
     */
    public static function digest($content);

    /**
     * Sets the cache control header
     *
     * @param {string} $value - The value to set it to
     * @return {Void}
     */
    public static function setControl($value);

    /**
     * Sets the cache expiration date by the offset in seconds
     *
     * @param {Integer} $offset - Offset in seconds
     * @return {Void}
     */
    public static function setExpiration($offset);

    /**
     * Directly sets the etag header
     *
     * @param {String} $etag - The etag to set the header to
     * @return {String}      - Returns the passed in etag
     */
    public static function setEtagDirectly($etag);

    /**
     * Sets the etag header to the signature of the supplied content
     *
     * @param {String} $content - Content to base etag signature off of
     * @return {String}         - Returns the computed etag
     */
    public static function setEtagFromContent($content);

    /**
     * Function for serving a cache hit response
     *
     * @return {Void}
     */
    public static function finalizeHit();

    /**
     * Function for serving a cache miss response
     *
     * @return {Void}
     */
    public static function finalizeMiss();

}
Something went wrong with that request. Please try again.