コード例 #1
0
        public bool TryGet(TKey key, out TView view)
        {
            var filter = GetFilter(key);

            try
            {
                var doc = _collection.Find(filter).SingleOrDefault();

                if (doc != null)
                {
                    using (var stream = new MemoryStream(doc.ToBson()))
                    {
                        view = _strategy.Deserialize <TView>(stream);

                        return(true);
                    }
                }
            }
            catch
            {
                // logging
            }

            view = default(TView);

            return(false);
        }
コード例 #2
0
        public bool TryGet(TKey key, out TEntity entity)
        {
            var name = GetName(key);

            byte[] bytes;

            if (_store.TryGetValue(name, out bytes))
            {
                using (var mem = new MemoryStream(bytes))
                {
                    entity = _strategy.Deserialize <TEntity>(mem);
                    return(true);
                }
            }

            entity = default(TEntity);

            return(false);
        }