Airship\Cabin\Hull\Blueprint\Blog::getCommentCache PHP Method

getCommentCache() public method

Returns the cache container for blog comments:
public getCommentCache ( ) : CacheInterface
return CacheInterface
    public function getCommentCache() : CacheInterface
    {
        if (\extension_loaded('apcu')) {
            return (new MemoryCache())->personalize('BlogCommentCache');
        }
        return new FileCache(ROOT . '/tmp/cache/comments');
    }

Usage Example

Example #1
0
 /**
  * @route ajax/blog_load_comments
  */
 public function loadComments()
 {
     if (IDE_HACKS) {
         $this->blog = new Blog();
     }
     $cache = $this->blog->getCommentCache();
     $blog = (string) ($_POST['blogpost'] ?? '');
     if (empty($blog)) {
         \Airship\json_response(['status' => 'error', 'message' => 'No blogpost ID provided']);
     }
     $cachedComments = $cache->get($blog);
     if ($cachedComments) {
         \Airship\json_response($cachedComments);
     }
     $this->fetchComments($cache, $blog);
 }