This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 
<?php

defined('C5_EXECUTE') or die("Access Denied.");

class Concrete5_Library_FilePageCache extends PageCache {

    public function getRecord($mixed) {
        $file = $this->getCacheFile($mixed);
        if (file_exists($file)) {
            $contents = file_get_contents($file);
            $record = @unserialize($contents);
            if ($record instanceof PageCacheRecord) {
                return $record;
            }
        }
    }

    protected function getCacheFile($mixed) {
        $key = $this->getCacheKey($mixed);
        if ($key) {
            $key = hash('sha256',$key);
            $filename = $key . '.cache';
            $dir = DIR_FILES_PAGE_CACHE . '/' . $key[0] . '/' . $key[1] . '/' . $key[2];
            if ($dir && (!is_dir($dir))) {
                @mkdir($dir, DIRECTORY_PERMISSIONS_MODE, true);
            }
            $path = $dir . '/' . $filename;
            return $path;
        }
    }

    public function purgeByRecord(PageCacheRecord $rec) {
        $file = $this->getCacheFile($rec);
        if ($file && file_exists($file)) {
            @unlink($file);
        }
    }

    public function flush() {
        $fh = Loader::helper("file");
        $fh->removeAll(DIR_FILES_PAGE_CACHE);
    }

    public function purge(Page $c) {
        $file = $this->getCacheFile($c);
        if ($file && file_exists($file)) {
            @unlink($file);
        }
    }

    public function set(Page $c, $content) {
        if (!is_dir(DIR_FILES_PAGE_CACHE)) {
            @mkdir(DIR_FILES_PAGE_CACHE);
            @touch(DIR_FILES_PAGE_CACHE . '/index.html');
        }

        $lifetime = $c->getCollectionFullPageCachingLifetimeValue();
        $file = $this->getCacheFile($c);
        if ($file) {
            $response = new PageCacheRecord($c, $content, $lifetime);
            if ($content) {
                file_put_contents($file, serialize($response));
            }
        }
    }


}