Elgg\ViewsService::isCacheableView PHP Method

isCacheableView() public method

public isCacheableView ( $view )
    public function isCacheableView($view)
    {
        $view = $this->canonicalizeViewName($view);
        if (isset($this->simplecache_views[$view])) {
            return true;
        }
        // build list of viewtypes to check
        $current_viewtype = elgg_get_viewtype();
        $viewtypes = array($current_viewtype);
        if ($this->doesViewtypeFallback($current_viewtype) && $current_viewtype != 'default') {
            $viewtypes[] = 'default';
        }
        // If a static view file is found in any viewtype, it's considered cacheable
        foreach ($viewtypes as $viewtype) {
            $file = $this->findViewFile($view, $viewtype);
            if ($file && pathinfo($file, PATHINFO_EXTENSION) !== 'php') {
                $this->simplecache_views[$view] = true;
                return true;
            }
        }
        // Assume not-cacheable by default
        return false;
    }

Usage Example

Example #1
0
 public function testStaticViewsAreAlwaysCacheable()
 {
     $this->assertTrue($this->views->isCacheableView('js/static.js'));
 }