BuildYourOwnDAL.SessionLevelCache.Store C# (CSharp) Method

Store() public method

public Store ( Type type, object id, object entity ) : void
type System.Type
id object
entity object
return void
        public void Store(Type type, object id, object entity)
        {
            if (!cache.ContainsKey(type)) cache.Add(type, new Dictionary<string, object>());

            cache[type][id.ToString()] = entity;
        }

Usage Example

Exemplo n.º 1
0
        private TEntity CreateEntityFromValues <TEntity>(IDictionary <string, object> values)
        {
            var tableInfo = metaDataStore.GetTableInfoFor <TEntity>();

            var cachedEntity = sessionLevelCache.TryToFind(typeof(TEntity), values[tableInfo.PrimaryKey.Name]);

            if (cachedEntity != null)
            {
                return((TEntity)cachedEntity);
            }

            var entity = Activator.CreateInstance <TEntity>();

            Hydrate(tableInfo, entity, values);
            sessionLevelCache.Store(typeof(TEntity), values[tableInfo.PrimaryKey.Name], entity);
            return(entity);
        }