/// <summary>
		/// Turns the given <paramref name="obj"/> in a cacheable object.
		/// </summary>
		/// <param name="obj">The <see cref="Record"/> for which to create the cacheable object.</param>
		/// <param name="query">The <see cref="Query"/> which resulted in the given <paramref name="obj"/>.</param>
		/// <returns>Returns the <see cref="CachedObject{TObject}"/>.</returns>
		public static CachedObject<Record> AsCacheableObject(this Record obj, Query query)
		{
			// validate arguments
			if (query == null)
				throw new ArgumentNullException("query");

			// create a new cacheable object
			var cacheable = new CachedObject<Record>(obj);

			// if the result is found, cache it by it's id
			ChildOfSpecification childOfSpecification;
			if (obj != null)
			{
				// generate an ID for this specific record
				var recordIdCacheKey = obj.CalculateIdCacheKey();

				// add that cache key as the dependency
				cacheable.Add((StringCacheKeyDependency) recordIdCacheKey);
			}
			else if (query.TryGetSpecification(out childOfSpecification))
			{
				// cache on the parent tree Id
				var parentTreeIdCacheKey = childOfSpecification.ParentPointer.CalculateTreeIdCacheKey();

				// add that cache key as the dependency
				cacheable.Add((StringCacheKeyDependency) parentTreeIdCacheKey);
			}
			else
			{
				// add the repository modified cache key
				cacheable.Add(CachingRepositoryDecorator.RepositoryModifiedDependency);
			}

			// return the cacheable  object
			return cacheable;
		}
		/// <summary>
		/// Clears the given <paramref name="node"/> from the <paramref name="cachingService"/>.
		/// </summary>
		/// <param name="node">The <see cref="Node"/> which should be cleared from the cache.</param>
		/// <param name="cachingService">The <see cref="ICachingService"/>.</param>
		/// <exception cref="ArgumentNullException">Thrown if one of the parameters is null.</exception>
		public static void ClearFromCache(this Node node, ICachingService cachingService)
		{
			// validate arguments
			if (node == null)
				throw new ArgumentNullException("node");
			if (cachingService == null)
				throw new ArgumentNullException("cachingService");

			// fire the evict by ID
			cachingService.Clear(node.CalculateIdCacheKey());

			// fire the evict by tree ID
			foreach (var treeCacheKey in node.Pointer.CalculateTreeIdCacheKeys())
				cachingService.Clear(treeCacheKey);

			// fire the repository modified
			cachingService.Clear(CachingRepositoryDecorator.RepositoryModifiedDependency.Key);
		}
		/// <summary>
		/// Clears the given <paramref name="record"/> from the <paramref name="cachingService"/>.
		/// </summary>
		/// <param name="record">The <see cref="Record"/> which should be cleared from the cache.</param>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="cachingService">The <see cref="ICachingService"/>.</param>
		/// <exception cref="ArgumentNullException">Thrown if one of the parameters is null.</exception>
		public static void ClearFromCache(this Record record, IMansionContext context, ICachingService cachingService)
		{
			// validate arguments
			if (record == null)
				throw new ArgumentNullException("record");
			if (context == null)
				throw new ArgumentNullException("context");
			if (cachingService == null)
				throw new ArgumentNullException("cachingService");

			// fire the evict by ID
			cachingService.Clear(record.CalculateIdCacheKey());

			// fire the evict by tree ID, if any
			NodePointer pointer;
			if (record.TryGet(context, "pointer", out pointer))
			{
				foreach (var treeCacheKey in pointer.CalculateTreeIdCacheKeys())
					cachingService.Clear(treeCacheKey);
			}

			// fire the repository modified
			cachingService.Clear(CachingRepositoryDecorator.RepositoryModifiedDependency.Key);
		}