Skip to content

Instantly share code, notes, and snippets.

@Geolim4
Created September 17, 2016 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Geolim4/bdccc41690c48605cff1c6cb37497f9e to your computer and use it in GitHub Desktop.
Save Geolim4/bdccc41690c48605cff1c6cb37497f9e to your computer and use it in GitHub Desktop.
    use phpFastCache\CacheManager;

    $cache = CacheManager::Memcached();

    $keyword_webpage = md5($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING']);
    // try to get from Cache first.
    $resultsItem = $cache->getItem($keyword_webpage)

    if(!$resultsItem->isHit()) {
        ob_start();
        /*
            ALL OF YOUR CODE GO HERE
            RENDER YOUR PAGE, DB QUERY, WHATEVER
        */

        // GET HTML WEBPAGE
        $html = ob_get_contents();

        $resultsItem->set($html)->expireAfter(1800);
        $cache->save($resultsItem);
    }

    echo $resultsItem->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment