Fragment
Kohana_Fragment

Class Contents

Constants

  • None

Properties

Class declared in SYSPATH/classes/fragment.php on line 3.

Properties

public static $i18n
bool FALSE
public static $lifetime
integer 30

Methods

protected static _cache_key( )
Kohana_Fragment

Source Code
protected static function _cache_key($name, $i18n = NULL)
{
	if ($i18n === NULL)
	{
		// Use the default setting
		$i18n = Fragment::$i18n;
	}

	// Language prefix for cache key
	$i18n = ($i18n === TRUE) ? I18n::lang() : '';

	// Note: $i18n and $name need to be delimited to prevent naming collisions
	return 'Fragment::cache('.$i18n.'+'.$name.')';
}

public static delete( )
Kohana_Fragment

Source Code
public static function delete($name, $i18n = NULL)
{
	// Invalid the cache
	Kohana::cache(Fragment::_cache_key($name, $i18n), NULL, -3600);
}

public static load( )
Kohana_Fragment

Source Code
public static function load($name, $lifetime = NULL, $i18n = NULL)
{
	// Set the cache lifetime
	$lifetime = ($lifetime === NULL) ? Fragment::$lifetime : (int) $lifetime;

	// Get the cache key name
	$cache_key = Fragment::_cache_key($name, $i18n);

	if ($fragment = Kohana::cache($cache_key, NULL, $lifetime))
	{
		// Display the cached fragment now
		echo $fragment;

		return TRUE;
	}
	else
	{
		// Start the output buffer
		ob_start();

		// Store the cache key by the buffer level
		Fragment::$_caches[ob_get_level()] = $cache_key;

		return FALSE;
	}
}

public static save( )
Kohana_Fragment

Source Code
public static function save()
{
	// Get the buffer level
	$level = ob_get_level();

	if (isset(Fragment::$_caches[$level]))
	{
		// Get the cache key based on the level
		$cache_key = Fragment::$_caches[$level];

		// Delete the cache key, we don't need it anymore
		unset(Fragment::$_caches[$level]);

		// Get the output buffer and display it at the same time
		$fragment = ob_get_flush();

		// Cache the fragment
		Kohana::cache($cache_key, $fragment);
	}
}