Example #1
0
        public CacheStatus Set(string key, string value, UInt32 flags, UInt32 expiry, UInt64 cas, out UInt64 newCas)
        {
            uint        tableSlot = ((uint)key.GetHashCode()) % Configuration.CacheTableSize;
            CacheStatus status    = CacheStatus.NoError;

            newCas = 0;

            lock (this.cacheTable[tableSlot])
            {
                CacheRecord record = null;

                if (!this.cacheTable[tableSlot].TryGetValue(key, out record))
                {
                    record = new CacheRecord {
                        Key = key
                    };
                    this.cacheTable[tableSlot] [key] = record;
                }

                if (cas == 0 || cas == record.CAS)
                {
                    record.Value  = value;
                    record.Flags  = flags;
                    record.Expiry = expiry;
                    record.CAS++;
                }
                else
                {
                    status = CacheStatus.CasDosentMatch;
                }
            }

            return(status);
        }
Example #2
0
        public CacheStatus Get(string key, out string value, out UInt32 flags)
        {
            uint        tableSlot = ((uint)key.GetHashCode()) % Configuration.CacheTableSize;
            CacheStatus status    = CacheStatus.NoError;

            lock (this.cacheTable[tableSlot])
            {
                CacheRecord record = null;

                if (this.cacheTable[tableSlot].TryGetValue(key, out record))
                {
                    value = record.Value;
                    flags = record.Flags;
                }
                else
                {
                    status = CacheStatus.KeyDoesNotExist;
                    value  = String.Empty;
                    flags  = 0;
                }
            }

            return(status);
        }