/// <summary> /// Delete from cache, optionally delete from Db /// </summary> /// <typeparam name="T"></typeparam> /// <param name="obj"></param> /// <param name="updateMasterDatabase"></param> /// <returns></returns> public async Task DeleteObject <T>(T obj, bool updateMasterDatabase = true) where T : IDatabaseModelBase { Db.KeyDelete(CacheHelper.CreateKey <T>(obj.Id)); if (updateMasterDatabase) { await DocumentCosmosDb.DeleteDocument(obj); } }
public async Task <string> UpsertDocumentOnly <T>(T value) where T : IDatabaseModelBase { Ensure.CheckForNull(value); value.id = CacheHelper.RemoveKeyPrefixes(value.Id); //store into doc db string documentDbId = await DocumentCosmosDb.UpsertDocument(value); //set Id of object, so redis will also have it value.Id = documentDbId; return(documentDbId); }
/// <summary> /// Retrieves an object from Redis first, then DocumentCosmosDb afterwards /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id"></param> /// <returns></returns> public T GetObject <T>(string id) { //first try cache T obj = GetObjectOnlyCache <T>(id); if (obj == null) { //now try docdb obj = DocumentCosmosDb.GetDocument <T>(id); } if (obj == null) { return(default(T)); } return(obj); }
/// <summary> /// Retrieves an object from Redis first, then DocumentCosmosDb afterwards /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id"></param> /// <returns></returns> public async Task <T> GetObjectAsync <T>(string id) { //first try cache T obj = await GetObjectOnlyCacheAsync <T>(id); if (obj == null) { //now try docdb obj = DocumentCosmosDb.GetDocument <T>(id); } if (obj == null) { return(default(T)); } return(obj); }