private DBCacheRecord CreateRecord(byte[] data, CacheItemID?ciid, byte[] key, CacheEntityType entityType, CacheMode cacheMode) { if (key.Length <= DBCacheRecord.KeySizeMaximum) { DBCacheRecord rec = new DBCacheRecord(); if (ciid.HasValue) { rec.CIID = ciid.Value.ToByteArray(); } else { rec.CIID = null; } rec.Key = key; rec.EntityType = (short)entityType; rec.CacheMode = (short)cacheMode; rec.SetData(data); return(rec); } return(null); }
long ICacheStore.Add(byte[] data, CacheItemID?ciid, byte[] key, CacheEntityType entityType, CacheMode cacheMode) { if (((key == null) && !ciid.HasValue) || (data == null)) { return(CacheStore.BadRecordID); } DBCacheRecord rec = CreateRecord(data, ciid, key, entityType, cacheMode); dc.ServerCache.InsertOnSubmit(rec); dc.SubmitChanges(); return(rec.ID); }
long[] ICacheStore.AddRange(List <CacheDataTemplate> items) { if ((items != null) && (items.Count > 0)) { DBCacheRecord[] records = new DBCacheRecord[items.Count]; long[] res = new long[items.Count]; for (int i = 0; i < items.Count; i++) { if ((items[i] == null) || ((items[i].Key == null) && !items[i].CIID.HasValue) || (items[i].Data == null)) { res[i] = CacheStore.BadRecordID; continue; } records[i] = CreateRecord(items[i].DataBinary, items[i].CIID, items[i].Key, items[i].EntityType, items[i].Mode ?? CacheMode.Persistant); } for (int i = 0; i < records.Length; i++) { if (records[i] != null) { dc.ServerCache.InsertOnSubmit(records[i]); } } dc.SubmitChanges(); for (int i = 0; i < records.Length; i++) { if (records[i] != null) { res[i] = records[i].ID; } else { res[i] = CacheStore.BadRecordID; } } return(res); } return(new long[0]); }