<?php
/*
 * Copyright (c) 2012, webvariants GbR, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

/**
 * Cache-Wrapper
 *
 * @author Christoph
 * @since  v4.0
 */
abstract class _WV24_Cache {
	public static function findURL($namespace, $ident) {
		$cacheNS = 'realurl2.ns.'.$namespace;
		return sly_Core::cache()->get($cacheNS, $ident);
	}

	public static function clear($namespace = null, $ident = null) {
		$cacheNS = 'realurl2'.($namespace === null ? '' : '.ns.'.$namespace);

		if ($ident !== null) {
			sly_Core::cache()->delete($cacheNS, $ident);
		}
		else {
			sly_Core::cache()->flush($cacheNS, true);
		}
	}

	public static function cacheURL(_WV24_URL $url) {
		$cacheNS  = 'realurl2.ns.'.$url->getNamespace();
		$cacheKey = $url->getIdent();

		sly_Core::cache()->set($cacheNS, $cacheKey, $url);

		// Do NOT set the URL based on its URI's hash here, as this might
		// overwrite another article's URL with higher priority!
//		sly_Core::cache()->set('realurl2.volatile', md5($url->getRawURL()), $url);
	}
}
