コード例 #1
0
 /// <summary>
 /// Adds the stecified item in the cache.
 /// </summary>
 /// <param name="id">The id of the stored item in the cache.</param>
 /// <param name="item">The item to cache.</param>
 protected void AddInCache(Identifier id, T item)
 {
     if (!InternalCache.ContainsKey(id))
     {
         InternalCache.Add(id, item);
     }
 }
コード例 #2
0
ファイル: CacheService.cs プロジェクト: Qorpent/qorpent.sys
        public TItem Get(string key, Func <string, TItem> retriever)
        {
            lock (this) {
                if (InternalCache.ContainsKey(key))
                {
                    Refresh(false);
                    if (InternalCache.ContainsKey(key))
                    {
                        return(InternalCache[key]);
                    }
                }
                var obj = retriever(key);
                InternalCache[key] = obj;

                return(obj);
            }
        }
コード例 #3
0
        protected override AppointmentDto Map(SQLiteDataReader reader)
        {
            var        rid = reader["Id"] as long?;
            Identifier id;

            if (!rid.HasValue)
            {
                throw new NullReferenceException("There's an appointment without ID");
            }
            else
            {
                id = new Identifier(rid.Value);
            }

            if (InternalCache.ContainsKey(id))
            {
                return(InternalCache[id]);
            }
            else
            {
                var item = new AppointmentDto()
                {
                    IsImported = true
                };

                item.StartTime = reader["StartDate"] as DateTime? ?? DateTime.Now;
                item.EndTime   = reader["EndDate"] as DateTime? ?? DateTime.Now;

                item.Subject = reader["Title"] as string;
                item.Notes   = Messages.Msg_DoneByConverter;
                item.User    = PluginContext.Host.ConnectedUser;
                item.Tag     = this.MapTag(reader["fk_MeetingType"] as long?);

                InternalCache.Add(id, item);

                return(item);
            }
        }
コード例 #4
0
        public T Import(long?rid)
        {
            Identifier id;

            if (!rid.HasValue || string.IsNullOrWhiteSpace(this.Sql(-1)))
            {
                return(this.Default);
            }
            else
            {
                id = new Identifier(rid.Value, this.Segragator);
            }

            if (InternalCache.ContainsKey(id))
            {
                return(InternalCache[id]);
            }
            else
            {
                using (var command = new SQLiteCommand(this.Sql(id.Value), this.Connection))
                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            var result = Map(reader);
                            this.AddInCache(new Identifier(id.Value, this.Segragator), result);
                            return(result);
                        }
                        else
                        {
                            this.OnLogged(Messages.Log_NoItem, id.Value);
                            this.AddInCache(new Identifier(id.Value, this.Segragator), this.Default);
                            return(this.Default);
                        }
                    }
            }
        }
コード例 #5
0
ファイル: AGroup.cs プロジェクト: Deigue/Mutagen
 /// <inheritdoc />
 public bool ContainsKey(FormKey key) => InternalCache.ContainsKey(key);
コード例 #6
0
 /// <summary>
 ///     Determines if the item exists
 /// </summary>
 /// <param name="key">The key associated with the item</param>
 /// <returns>True if it does, false otherwise</returns>
 public virtual bool Exists(TKeyType key)
 {
     return(InternalCache.ContainsKey(key));
 }
コード例 #7
0
ファイル: CacheService.cs プロジェクト: Qorpent/qorpent.sys
 public bool Exists(string key)
 {
     return(InternalCache.ContainsKey(key));
 }