private void InitializeWorks() { Action <uint, IWork> entityLoaded = (id, entity) => workCache.Add(id, entity); Action <uint, ILink, uint> linkLoaded = (id, link, entityId) => { var entity = workCache.GetEntity(entityId); if (entity != null) { entity.AddLink(link); workCache.Add(id, entity, link); } }; Action <uint, ITag, uint> tagLoaded = (id, tag, entityId) => { var entity = workCache.GetEntity(entityId); if (entity != null) { entity.AddTag(tag); workCache.Add(id, entity, tag); } }; workStore.Initialize(entityLoaded, linkLoaded, tagLoaded); }
private async Task <T> _get(Guid id, Func <Task <T> > sourceTask, TimeSpan?maxAge) { var memory = _memoryCache.FirstOrDefault(_ => _.Id == id); if (memory != null) { return(memory); } using (var lRead = await XNamedLock.Get("entm_" + id).LockAsync()) { T cache = null; if (sourceTask != null) { cache = await _entityCache.GetEntity <T>(_getKey(id), sourceTask); } else { cache = await _entityCache.GetEntity <T>(_getKey(id)); } if (cache == null) { return(null); } var cResult = await Set(cache, maxAge); return(cResult); } }
private void InitializeArtists() { Action <uint, IArtist> entityLoaded = (id, entity) => artistCache.Add(id, entity); Action <uint, ILink, uint> linkLoaded = (id, link, entityId) => { var entity = artistCache.GetEntity(entityId); if (entity != null) { entity.AddLink(link); artistCache.Add(id, entity, link); } }; Action <uint, ITag, uint> tagLoaded = (id, tag, entityId) => { var entity = artistCache.GetEntity(entityId); if (entity != null) { entity.AddTag(tag); artistCache.Add(id, entity, tag); } }; artistStore.Initialize(entityLoaded, linkLoaded, tagLoaded); }
public async Task Init() { var dumps = await _cache.GetEntity <ObservableCollection <DumpWireEntity> >(DumpConstants.LocalDumpFileName); if (dumps != null) { _dumps = dumps; } }
async Task <List <GeneralSettingsEntity> > _getCache() { //note there is no async lock here, it's to be handled by the caller var settings = await _entityCache.GetEntity <List <GeneralSettingsEntity> >(SETTINGS_KEY); if (settings == null) { settings = new List <GeneralSettingsEntity>(); await _entityCache.SetEntity(SETTINGS_KEY, settings); } return(settings); }
private IGraphEntity LoadGraphEntity(string propertyName, JToken record, Dictionary <string, object> itemproperties, Type propertyType) { IGraphEntity graphEntity = null; var entityPropertyNames = new EntityReturnColumns(propertyName); AssertNecesaryColumnForType(entityPropertyNames.IdPropertyName, typeof(IGraphEntity)); var recordIsArray = record.GetType().IsAssignableFrom(typeof(JArray)); var entityId = recordIsArray ? record[_propertyCache[entityPropertyNames.IdPropertyName]].Value <long>() : record["row"][_propertyCache[entityPropertyNames.IdPropertyName]].Value <long>(); if (_cache.Contains(entityId, propertyType)) { graphEntity = _cache.GetEntity(entityId, propertyType); } else { itemproperties.Add("id", entityId); AssertNecesaryColumnForType(entityPropertyNames.PropertiesPropertyName, typeof(IGraphEntity)); var entityProperties = recordIsArray ? record[_propertyCache[entityPropertyNames.PropertiesPropertyName]] .ToObject <Dictionary <string, object> >() : record["row"][_propertyCache[entityPropertyNames.PropertiesPropertyName]].ToObject <Dictionary <string, object> >(); itemproperties.Add("properties", entityProperties); if (typeof(Node).IsAssignableFrom(propertyType)) { AssertNecesaryColumnForType(entityPropertyNames.LabelsPropertyName, typeof(Node)); var labels = entityProperties.Keys.ToArray(); itemproperties.Add("labels", labels); } else { AssertNecesaryColumnForType(entityPropertyNames.TypePropertyName, typeof(Relationship)); var relType = recordIsArray ? record[_propertyCache[entityPropertyNames.TypePropertyName]].ToObject <string>() : record["row"][_propertyCache[entityPropertyNames.TypePropertyName]].ToObject <string>(); itemproperties.Add("type", relType); } graphEntity = (IGraphEntity)HydrateWithCtr(itemproperties, propertyType); _cache.CacheEntity(graphEntity); } return(graphEntity); }
protected override void LoadEntity(IDataRecord record, Action <uint, IWork> entityLoaded) { var id = (uint)record.GetInt64(0); var type = (WorkType)record.GetInt32(1); var parentId = (uint)record.GetInt64(2); var artist = artistCache.GetEntity((uint)record.GetInt64(3)); var name = record.GetString(4); var year = record.GetInt16(5); var number = (uint)record.GetInt64(6); AddPostLoadAction(() => { var work = workCache.GetEntity(id); if (work == null) { return; } work.Parent = workCache.GetEntity(parentId); }); entityLoaded(id, new Work(type, null, artist, name, year, number)); }
async Task _init() { if (_buckets != null) { return; } using (var l = await _lock.LockAsync()) { var bucketKey = _getThisBucketKey(); _buckets = await _cache.GetEntity <Dictionary <string, List <Guid> > >(bucketKey); if (_buckets == null) { _buckets = new Dictionary <string, List <Guid> >(); await _save(); } } }