private static void InitializeSchemaCacheItem(RepositoryCacheItem cacheItem)
        {
            using (var context = new DatastoreEntities())
            {
                var r = context.Repository.FirstOrDefault(x => x.UniqueKey == cacheItem.Key && !x.IsDeleted && x.IsInitialized);
                if (r == null)
                {
                    cacheItem.IsInitialized = true;
                    cacheItem.Exists        = false;
                    return;
                }
                ;

                var retval = new RepositorySchema
                {
                    InternalID  = r.RepositoryId,
                    ChangeStamp = r.Changestamp
                };
                retval.LoadXml(r.DefinitionData);

                cacheItem.IsInitialized = true;
                cacheItem.Exists        = true;
                cacheItem.Xml           = retval.ToXml(true);
                cacheItem.VersionHash   = retval.VersionHash; // Cache the version to reduce number of calculations
                cacheItem.InternalId    = retval.InternalID;
                cacheItem.HasParent     = (r.ParentId != null);
            }
        }
        private void ClearSchemaCacheItem(RepositoryCacheItem cacheItem)
        {
            if (cacheItem.IsInitialized && cacheItem.Exists)
            {
                _schemaParentCache.TryRemove(cacheItem.InternalId, out var _);
            }

            cacheItem.IsInitialized = false;
            cacheItem.Xml           = null;
        }
        private static bool TryGetCachedSchemaValue <T>(RepositoryCacheItem cacheItem, Func <RepositoryCacheItem, T> valueGetter, out T value)
        {
            value = default(T);
            using (cacheItem.EnterReadLock(LockTimeOut))
            {
                if (cacheItem.IsInitialized)
                {
                    value = cacheItem.Exists ? valueGetter(cacheItem) : default(T);
                    return(true);
                }

                return(false);
            }
        }