executes & returns or displays the template results

@param string $resource_name
@param string $cache_id
@param string $compile_id
@param boolean $display
170800
function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)
	{
		static $_cache_info = array();

		$_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting)
		? $this->error_reporting : error_reporting() & ~E_NOTICE);

		if (!$this->debugging && $this->debugging_ctrl == 'URL') {
			$_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'];
			if (@strstr($_query_string, $this->_smarty_debug_id)) {
				if (@strstr($_query_string, $this->_smarty_debug_id . '=on')) {
					// enable debugging for this browser session
					@setcookie('SMARTY_DEBUG', true);
					$this->debugging = true;
				} elseif (@strstr($_query_string, $this->_smarty_debug_id . '=off')) {
					// disable debugging for this browser session
					@setcookie('SMARTY_DEBUG', false);
					$this->debugging = false;
				} else {
					// enable debugging for this page
					$this->debugging = true;
				}
			} else {
				$this->debugging = (bool)($this->request_use_auto_globals ? @$_COOKIE['SMARTY_DEBUG'] : @$GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']);
			}
		}

		if ($this->debugging) {
			// capture time for debugging info
			$_params = array();
			require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
			$_debug_start_time = smarty_core_get_microtime($_params, $this);
			$this->_smarty_debug_info[] = array('type'      => 'template',
                                                'filename'  => $resource_name,
                                                'depth'     => 0);
			$_included_tpls_idx = count($this->_smarty_debug_info) - 1;
		}

		if (!isset($compile_id)) {
			$compile_id = $this->compile_id;
		}

		$this->_compile_id = $compile_id;
		$this->_inclusion_depth = 0;

		if ($this->caching) {
			// save old cache_info, initialize cache_info
			array_push($_cache_info, $this->_cache_info);
			$this->_cache_info = array();
			$_params = array(
                'tpl_file' => $resource_name,
                'cache_id' => $cache_id,
                'compile_id' => $compile_id,
                'results' => null
			);
			require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php');
			if (smarty_core_read_cache_file($_params, $this)) {
				$_smarty_results = $_params['results'];
				if (!empty($this->_cache_info['insert_tags'])) {
					$_params = array('plugins' => $this->_cache_info['insert_tags']);
					require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
					smarty_core_load_plugins($_params, $this);
					$_params = array('results' => $_smarty_results);
					require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php');
					$_smarty_results = smarty_core_process_cached_inserts($_params, $this);
				}
				if (!empty($this->_cache_info['cache_serials'])) {
					$_params = array('results' => $_smarty_results);
					require_once(SMARTY_CORE_DIR . 'core.process_compiled_include.php');
					$_smarty_results = smarty_core_process_compiled_include($_params, $this);
				}


				if ($display) {
					if ($this->debugging)
					{
						// capture time for debugging info
						$_params = array();
						require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
						$this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time;
						require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');
						$_smarty_results .= smarty_core_display_debug_console($_params, $this);
					}
					if ($this->cache_modified_check) {
						$_server_vars = ($this->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
						$_last_modified_date = @substr($_server_vars['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
						$_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';
						if (@count($this->_cache_info['insert_tags']) == 0
						&& !$this->_cache_serials
						&& $_gmt_mtime == $_last_modified_date) {
							if (php_sapi_name()=='cgi')
							header('Status: 304 Not Modified');
							else
							header('HTTP/1.1 304 Not Modified');

						} else {
							header('Last-Modified: '.$_gmt_mtime);
							echo $_smarty_results;
						}
					} else {
						echo $_smarty_results;
					}
					error_reporting($_smarty_old_error_level);
					// restore initial cache_info
					$this->_cache_info = array_pop($_cache_info);
					return true;
				} else {
					error_reporting($_smarty_old_error_level);
					// restore initial cache_info
					$this->_cache_info = array_pop($_cache_info);
					return $_smarty_results;
				}
			} else {
				$this->_cache_info['template'][$resource_name] = true;
				if ($this->cache_modified_check && $display) {
					header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
				}
			}
		}

		// load filters that are marked as autoload
		if (count($this->autoload_filters)) {
			foreach ($this->autoload_filters as $_filter_type => $_filters) {
				foreach ($_filters as $_filter) {
					$this->load_filter($_filter_type, $_filter);
				}
			}
		}

		$_smarty_compile_path = $this->_get_compile_path($resource_name);

		// if we just need to display the results, don't perform output
		// buffering - for speed
		$_cache_including = $this->_cache_including;
		$this->_cache_including = false;
		if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {
			if ($this->_is_compiled($resource_name, $_smarty_compile_path)
			|| $this->_compile_resource($resource_name, $_smarty_compile_path))
			{
				include($_smarty_compile_path);
			}
		} else {
			ob_start();
			if ($this->_is_compiled($resource_name, $_smarty_compile_path)
			|| $this->_compile_resource($resource_name, $_smarty_compile_path))
			{
				include($_smarty_compile_path);
			}
			$_smarty_results = ob_get_contents();
			ob_end_clean();

			foreach ((array)$this->_plugins['outputfilter'] as $_output_filter) {
				$_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this));
			}
		}

		if ($this->caching) {
			$_params = array('tpl_file' => $resource_name,
                        'cache_id' => $cache_id,
                        'compile_id' => $compile_id,
                        'results' => $_smarty_results);
			require_once(SMARTY_CORE_DIR . 'core.write_cache_file.php');
			smarty_core_write_cache_file($_params, $this);
			require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php');
			$_smarty_results = smarty_core_process_cached_inserts($_params, $this);

			if ($this->_cache_serials) {
				// strip nocache-tags from output
				$_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s'
				,''
				,$_smarty_results);
			}
			// restore initial cache_info
			$this->_cache_info = array_pop($_cache_info);
		}
		$this->_cache_including = $_cache_including;

		if ($display) {
			if (isset($_smarty_results)) { echo $_smarty_results; }
			if ($this->debugging) {
				// capture time for debugging info
				$_params = array();
				require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
				$this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time);
				require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');
				echo smarty_core_display_debug_console($_params, $this);
			}
			error_reporting($_smarty_old_error_level);
			return;
		} else {
			error_reporting($_smarty_old_error_level);
			if (isset($_smarty_results)) { return $_smarty_results; }
		}
	}
1040839
def cache_results(&block)
        return yield unless template_cache_configured? && defined?(@_cache_key)

        if cache_read_on_render?
          fetch_result_from_cache(cache_key, @_cache_options, &block)
        else
          write_result_to_cache(cache_key, @_cache_options, &block)
        end
      end
386752
static function insert_cached_document(CPDF_Adapter $pdf, $id, $new_page = true) {
    $res = self::__query("SELECT font_name FROM page_fonts WHERE id='" . pg_escape_string($id) . "'");

    // Ensure that the fonts needed by the cached document are loaded into
    // the pdf
    while ($row = pg_fetch_assoc($res)) 
      $pdf->get_cpdf()->selectFont($row["font_name"]);
    
    $res = self::__query("SELECT data FROM page_cache WHERE id='" . pg_escape_string($id) . "'");

    if ( $new_page )
      $pdf->new_page();

    $first = true;
    while ($row = pg_fetch_assoc($res)) {

      if ( !$first ) 
        $pdf->new_page();
      else 
        $first = false;        
      
      $page = $pdf->reopen_serialized_object($row["data"]);
      //$pdf->close_object();
      $pdf->add_object($page, "add");

    }
      
  }
563540
protected function getMethodTemplate($template_name, array $order, array $method)
    {
        if (empty($method['status']) || empty($method['template'][$template_name])) {
            return '';
        }

        $settings = array();
        $template = $method['template'][$template_name];

        if (!empty($method['module'])) {
            $template = "{$method['module']}|$template";
            $settings = $this->getModuleSettings($method['module']);
        }

        $data = array(
            'order' => $order,
            'method' => $method,
            'settings' => $settings
        );

        return $this->render($template, $data);
    }
735936
public function read_cache($cache_id)
	{
		// make sure we have all config data
		empty($this->cache_dir) and $this->cache_dir = \Config::get('cache_dir', APPPATH.'cache/');
		empty($this->cache_lifetime) and $this->cache_lifetime = \Config::get('cache_lifetime', 3600);

		if ($cached = $this->cache($cache_id))
		{
			$this->cached_paths = $cached;
		}
	}
569602
@Override
	public void cacheResult(CPDisplayLayout cpDisplayLayout) {
		entityCache.putResult(CPDisplayLayoutModelImpl.ENTITY_CACHE_ENABLED,
			CPDisplayLayoutImpl.class, cpDisplayLayout.getPrimaryKey(),
			cpDisplayLayout);

		finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
			new Object[] { cpDisplayLayout.getUuid(), cpDisplayLayout.getGroupId() },
			cpDisplayLayout);

		finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
			new Object[] {
				cpDisplayLayout.getClassNameId(), cpDisplayLayout.getClassPK()
			}, cpDisplayLayout);

		cpDisplayLayout.resetOriginalValues();
	}
21890
public static function renderThemeTemplate($target, $templateId, $data = array()){

        //search in the registry to get the custom template to render
        $tpl = self::getThemeTemplate($target, $templateId);
        $theme = self::getCurrentTheme();

        if(!is_null($tpl)){
            if ($theme instanceof ConfigurablePlatformTheme) {
                // allow to use the getters from ConfigurablePlatformTheme
                // to insert logo and such
                $data['themeObj'] = $theme;
            }
            //render the template
            $renderer = new \Renderer($tpl, $data);
            return $renderer->render();
        }
        return '';
    }
679327
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
    {
        $_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null;
        $_compile_id = isset($cached->compile_id) ? preg_replace('![^\w\|]+!', '_', $cached->compile_id) : null;

        $cached->filepath = sha1($cached->source->filepath . $_cache_id . $_compile_id);
        $this->populateTimestamp($cached);
    }
560433
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
    {
        $cached->filepath = $_template->source->uid
                . '#' . $this->sanitize($cached->source->resource)
                . '#' . $this->sanitize($cached->cache_id)
                . '#' . $this->sanitize($cached->compile_id);

        $this->populateTimestamp($cached);
    }
728677
final protected function display (bool $return=FALSE)
	{
		if (file_exists($this->file)):
			$output = file_get_contents($this->file);
			foreach ($this->assignedVariables as $key => $value) 
				$output = preg_replace('/{'.$key.'}/', $value, $output);
		else:
			$output = "*** Missing template error: {$this->file} ***";
		endif;

		if ($return)
			return $output;
		else
			echo $output;
	}
472942
function hasCompiledTemplate( $keyData, $uri, &$resourceData, $templatePath, &$extraParameters, $timestamp )
    {
        $key = $this->cacheKey( $keyData, $resourceData, $templatePath, $extraParameters );
        return eZTemplateCompiler::hasCompiledTemplate( $key, $timestamp, $resourceData );
    }
155452
protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
    {
        $now = microtime(true);
        $key = null;
        // invalidate everything
        if (!$resource_name && !$cache_id && !$compile_id) {
            $key = 'IVK#ALL';
        } // invalidate all caches by template
        else {
            if ($resource_name && !$cache_id && !$compile_id) {
                $key = 'IVK#TEMPLATE#' . $resource_uid . '#' . $this->sanitize($resource_name);
            } // invalidate all caches by cache group
            else {
                if (!$resource_name && $cache_id && !$compile_id) {
                    $key = 'IVK#CACHE#' . $this->sanitize($cache_id);
                } // invalidate all caches by compile id
                else {
                    if (!$resource_name && !$cache_id && $compile_id) {
                        $key = 'IVK#COMPILE#' . $this->sanitize($compile_id);
                    } // invalidate by combination
                    else {
                        $key = 'IVK#CID#' . $cid;
                    }
                }
            }
        }
        $this->write(array($key => $now));
    }
1334138
function compileTemplate( $tpl, $keyData, $uri, $res, $templatePath, &$extraParameters, &$resourceData )
    {
        $key = $this->cacheKey( $keyData, $res, $templatePath, $extraParameters );
        return eZTemplateCompiler::compileTemplate( $tpl, $key, $resourceData );
    }
200977
public function display_render( $pre_output, $field, $display ) {
		if ( ! empty( $pre_output ) ) {
			return $pre_output;
		}

		$return = '';

		// If repeatable
		if ( $display->field->args( 'repeatable' ) ) {
			$rows = array();

			// And has a repeatable value
			if ( is_array( $display->field->value ) ) {

				// Then loop and output.
				foreach ( $display->field->value as $val ) {
					$rows[] = $this->_display_render( $display->field, $val );
				}
			}

			if ( ! empty( $rows ) ) {

				$return .= '<ul class="cmb2-' . str_replace( '_', '-', $display->field->type() ) . '"><li>';
				foreach ( (array) $rows as $row ) {
					$return .= sprintf( '<li>%s</a>', $row );
				}
				$return .= '</ul>';

			} else {
				$return .= '&mdash;';
			}

		} else {
			$return .= $this->_display_render( $display->field, $display->field->value );
		}

		return $return ? $return : $pre_output;
	}
337286
public void onRequest(String template, int source) {
        final String methodName = "onRequest()";

        CacheStatsModule csm = null;
        if ((csm = getCSM(template)) == null) {
            return;
        }
        if (tc.isDebugEnabled())
            Tr.debug(tc, methodName + " cacheName=" + _sCacheName + " template=" + template + " source=" + source + " enable=" + csm._enable + " "
                    + this);
        if (csm._enable) {
            if (source == LOCAL) {
                if (csm._clientRequestCount != null)
                    csm._clientRequestCount.increment();
            } else if (source == REMOTE) {
                if (csm._distributedRequestCount != null)
                    csm._distributedRequestCount.increment();
            }
        }
        return;
    }
1324551
public function display($result, $method = 'info')
    {
        if ($result) {
            if (is_array($result)) {
                $this->displayTable($result);
            } elseif (is_bool($result)) {
                $this->{$method}($result ? 'Statement executed sucessfully.' : 'And error ocurred while executing the statement.');
            } else {
                $this->{$method}($result);
            }
        }
    }
923340
protected function getTemplateUid(Smarty $smarty, $resource_name, $cache_id, $compile_id)
    {
        $uid = '';
        if (isset($resource_name)) {
            $tpl = new $smarty->template_class($resource_name, $smarty);
            if ($tpl->source->exists) {
                $uid = $tpl->source->uid;
            }

            // remove from template cache
            if ($smarty->allow_ambiguous_resources) {
                $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
            } else {
                $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
            }
            if (isset($_templateId[150])) {
                $_templateId = sha1($_templateId);
            }
            unset($smarty->template_objects[$_templateId]);
        }

        return $uid;
    }