Пример #1
0
        internal async Task <IEntity> GetConcrete(object entityID, Type concreteType)
        {
            var result = Cache.Get(concreteType, entityID.ToString());

            if (result != null)
            {
                return(result);
            }

            var timestamp = Cache.GetQueryTimestamp();

            result = await FromDatabase(entityID, concreteType);

            // Don't cache the result if it is fetched in a transaction.
            if (result != null)
            {
                TryCache(result, timestamp);
            }

            return(result);
        }
Пример #2
0
        async Task <List <IEntity> > LoadFromDatabaseAndCache()
        {
            var timestamp = Cache.GetQueryTimestamp();

            var result = new List <IEntity>();

            foreach (var item in await LoadFromDatabase())
            {
                var inCache = Cache.Get(item.GetType(), item.GetId().ToString());
                if (inCache != null)
                {
                    result.Add(inCache);
                }
                else
                {
                    (Context.Current.Database() as Database)?.TryCache(item, timestamp);
                    result.Add(item);
                }
            }

            return(result);
        }
Пример #3
0
        async Task <List <IEntity> > LoadFromDatabaseAndCache()
        {
            var timestamp = Cache.GetQueryTimestamp();

            var result = new List <IEntity>();

            foreach (var item in await LoadFromDatabase())
            {
                var inCache = Cache.Current.Get(item.GetType(), item.GetId().ToString());
                if (inCache != null)
                {
                    result.Add(inCache);
                }
                else
                {
                    await EntityManager.RaiseOnLoaded(item);

                    Database.Instance.TryCache(item, timestamp);
                    result.Add(item);
                }
            }

            return(result);
        }