Пример #1
0
 public void Put <T>(string key, T item)
 {
     lock (_padlock)
     {
         SqlCache.Put(key, item.ToByteArray());
         InMemoryCache.Put(key, item);
     }
 }
Пример #2
0
        public WheelEntity Get(WheelFilter filter)
        {
            var wheel = _inMemoryCache.Get(filter.ManufacturerName);

            if (wheel == null)
            {
                wheel = _repository.Get(filter);

                _inMemoryCache.Put(filter.ManufacturerName, wheel);
            }

            return(wheel);
        }
Пример #3
0
        public CarPaintEntity Get(PaintFilter filter)
        {
            var paint = _inMemoryCache.Get(filter.Name);

            if (paint == null)
            {
                paint = _repository.Get(filter);

                _inMemoryCache.Put(filter.Name, paint);
            }

            return(paint);
        }
Пример #4
0
        public TyreEntity Get(TyreFilter filter)
        {
            var tyre = _inMemoryCache.Get(filter.WheelManufacturerName);

            if (tyre == null)
            {
                tyre = _repository.Get(filter);

                _inMemoryCache.Put(filter.WheelManufacturerName, tyre);
            }

            return(tyre);
        }
Пример #5
0
        public CarEngineEntity Get(EngineFilter filter)
        {
            var engine = _inMemoryCache.Get(filter.ManufacturerName);

            if (engine == null)
            {
                engine = _repository.Get(filter);

                _inMemoryCache.Put(filter.ManufacturerName, engine);
            }

            return(engine);
        }
Пример #6
0
    private T TryGetFromMemoryThenFromSource <T>(string key)
    {
        T cacheItem;

        lock (_padlock)
        {
            cacheItem = InMemoryCache.Get <T>(key);
            if (cacheItem == null)
            {
                // Key not in cache, so get data.
                cacheItem = SqlCache.Get <T>(key);
                if (cacheItem != null)
                {
                    InMemoryCache.Put(key, cacheItem);
                }
            }
        }
        return(cacheItem);
    }