예제 #1
0
        public async Task <string> Handle(TransferQRFileCommand command, CancellationToken token)
        {
            var id       = Guid.NewGuid().ToString();
            var cacheKey = $"file-{id}";
            await _store.Add(cacheKey, command.File, token);

            return(id);
        }
예제 #2
0
        public bool Add(object data, CacheItemID?ciid, byte[] key, CacheEntityType entityType, byte cacheHint = 0, bool cacheLiveData = false)
        {
            if (store != null)
            {
                if ((!ciid.HasValue && (key == null)) || (data == null))
                {
                    return(false);
                }

                bool isSession    = (cacheHint & ((byte)CacheHint.SessionStore_MayCache | (byte)CacheHint.SessionStore_ShouldCache)) > 0;
                bool isPersistent = (cacheHint & ((byte)CacheHint.PersistStore_MayCache | (byte)CacheHint.PersistStore_ShouldCache)) > 0;

                // determine cache mode
                CacheMode?mode = null;

                if (isPersistent)
                {
                    mode = CacheMode.Persistant;
                }
                else if (isSession)
                {
                    mode = CacheMode.Session;
                }

                // add to cache
                if (mode.HasValue)
                {
                    byte[] packed = CacheHelper.Pack(data);

                    if (packed != null)
                    {
                        long recordID = store.Add(packed, ciid, key, entityType, mode.Value);

                        if (recordID != BadRecordID)
                        {
                            indices.Add(ciid, key, recordID);

                            if (cacheLiveData)
                            {
                                AddLiveEntity(ciid, key, data);
                            }

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
예제 #3
0
        public List <ConversionRate> GetConversionRates()
        {
            ConversionRatesCache ratesCache = _cacheStore.Get(new ConversionRatesCacheKey());

            if (ratesCache != null)
            {
                return(ratesCache.Rates);
            }

            List <ConversionRate> rates = GetConversionRatesFromExternalApi();

            _cacheStore.Add(new ConversionRatesCache(rates), new ConversionRatesCacheKey(),
                            DateTime.Now.Date.AddDays(1));

            return(rates);
        }
예제 #4
0
        public async Task <ActionResult <IEnumerable <Country> > > GetCountriesUsingCacheStore()
        {
            // Tratar de obtener el Dato (La Lista de Paises) desde el cache
            List <Country> countries = _cacheStore.Get <List <Country> >("Countries");

            // Validar si el dato NO esta en el cache
            if (countries is null)
            {
                // Obtener el dato desde la Fuente
                countries = await GetCountries();

                // Adicionar el dato al cache
                _cacheStore.Add <List <Country> >("Countries", countries);
            }
            else
            {
                Console.WriteLine("Trayendo datos del Cache");
            }

            return(countries);
        }