예제 #1
0
        public bool AddRange(List <CacheDataTemplate> items, bool cacheLiveData = false)
        {
            if ((store != null) && (items != null) && (items.Count > 0))
            {
                List <CacheDataTemplate> records = new List <CacheDataTemplate>(items.Count);

                foreach (CacheDataTemplate item in items)
                {
                    if ((item == null) || (!item.CIID.HasValue && (item.Key == null)) || (item.Data == null))
                    {
                        continue;
                    }

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

                    // determine cache mode
                    if (isPersistent)
                    {
                        item.Mode = CacheMode.Persistant;
                    }
                    else if (isSession)
                    {
                        item.Mode = CacheMode.Session;
                    }
                    else
                    {
                        item.Mode = null;
                    }

                    // add to cache
                    if (item.Mode.HasValue)
                    {
                        item.DataBinary = CacheHelper.Pack(item.Data);

                        if (item.DataBinary != null)
                        {
                            records.Add(item);
                        }
                    }
                }

                long[] IDs = store.AddRange(records);

                for (int i = 0; i < IDs.Length; i++)
                {
                    if (IDs[i] != BadRecordID)
                    {
                        indices.Add(records[i].CIID, records[i].Key, IDs[i]);

                        if (cacheLiveData)
                        {
                            AddLiveEntity(records[i].CIID, records[i].Key, records[i].Data);
                        }
                    }
                }

                return(true);
            }

            return(false);
        }