Exemple #1
0
        public IEnumerable <string> AllKeys(string pattern, Server server, int pageSize)
        {
            if (pattern != "*")
            {
                throw new NotImplementedException("Only '*' pattern valid for LocalCache");
            }

            var ret = new List <string>();

            lock (_lock)
            {
                var e = HttpRuntime.Cache.GetEnumerator();

                while (e.MoveNext())
                {
                    var key = e.Key.ToString();

                    if (KeyUniquifier.IsPerSiteString(key, db))
                    {
                        ret.Add(KeyUniquifier.StripPerSiteString(key));
                    }
                }
            }

            return(ret);
        }
Exemple #2
0
        private void Push(IRedisConnection connection)
        {
            if (!connection.CanWrite)
            {
                return;                       // just don't bother... yet
            }
            // sets
            var toPush = new List <Tuple <string, HashSet <byte[]> > >();

            // ints
            var toIncrement = new List <Tuple <string, long> >();

            // Everything else can take a hike, as they're hard to merge

            var keys = FallbackKeys();

            lock (_lock)
            {
                foreach (var e in keys)
                {
                    var o = Get <object>(e, Server.DemandMaster);

                    var  s = o as HashSet <byte[]>;
                    long?i = o is long?(long?)((long)o) : null;

                    if (s != null)
                    {
                        toPush.Add(new Tuple <string, HashSet <byte[]> >(e, new HashSet <byte[]>(s)));  // a copy so we don't get boned when we release the lock
                    }
                    if (i.HasValue)
                    {
                        toIncrement.Add(new Tuple <string, long>(e, i.Value));
                    }
                }
            }

            int id, db = Db;

            foreach (var set in toPush)
            {
                var setName = set.Item1.Substring(1);

                if (KeyUniquifier.IsPerSiteString(setName, db))
                {
                    setName = KeyUniquifier.StripPerSiteString(setName, out id);
                }
                else
                {
                    id = 0;
                }

                lock (_lock)
                {
                    foreach (var i in set.Item2)
                    {
                        _target.AddToSet(setName, i);
                    }
                }
                Remove(setName);
            }

            foreach (var i in toIncrement)
            {
                var key = i.Item1.Substring(1);

                if (KeyUniquifier.IsPerSiteString(key, db))
                {
                    key = KeyUniquifier.StripPerSiteString(key, out id);
                }
                else
                {
                    id = 0;
                }

                lock (_lock)
                {
                    _target.IncrementInt(key, (int)i.Item2);
                }
                Remove(key);
            }
        }
Exemple #3
0
 public virtual string KeyInContext(string key)
 {
     return(db == 0 ? key : KeyUniquifier.UniquePerSiteString(db, key));
 }