|
@@ -638,7 +638,15 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
CosmosModelInfo container = await InitializeCollection<T>();
|
|
|
ItemResponse<T> response = await container.container.CreateItemAsync<T>(entity);
|
|
|
if (container.cache && RedisHelper.Instance!=null) {
|
|
|
- await RedisHelper.HSetAsync(CacheCosmosPrefix+container.container.Id, entity.id, entity);
|
|
|
+ if (!RedisHelper.Exists(CacheCosmosPrefix + container.container.Id))
|
|
|
+ {
|
|
|
+ await RedisHelper.HSetAsync(CacheCosmosPrefix + container.container.Id, entity.id, entity);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ await RedisHelper.HSetAsync(CacheCosmosPrefix + container.container.Id, entity.id, entity);
|
|
|
+ await RedisHelper.ExpireAsync(CacheCosmosPrefix + container.container.Id, timeoutSeconds);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
return response.Resource;
|
|
|
}
|
|
@@ -650,8 +658,15 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
|
|
|
public async Task<List<T>> SaveAll<T>(List<T> enyites) where T : ID
|
|
|
{
|
|
|
+
|
|
|
+
|
|
|
int pages = (int)Math.Ceiling((double)enyites.Count / pageSize);
|
|
|
CosmosModelInfo container = await InitializeCollection<T>();
|
|
|
+ bool flag = false;
|
|
|
+ if (RedisHelper.Exists(CacheCosmosPrefix + container.container.Id))
|
|
|
+ {
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
string pk = GetPartitionKey<T>();
|
|
|
Type type = typeof(T);
|
|
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
|
@@ -692,6 +707,9 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ if (container.cache && RedisHelper.Instance != null&&!flag) {
|
|
|
+ await RedisHelper.ExpireAsync(CacheCosmosPrefix + container.container.Id, timeoutSeconds);
|
|
|
+ }
|
|
|
stopwatch.Stop();
|
|
|
return enyites;
|
|
|
}
|
|
@@ -701,7 +719,15 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
ItemResponse<T> response = await container.container.UpsertItemAsync(item: entity);
|
|
|
if (container.cache && RedisHelper.Instance != null)
|
|
|
{
|
|
|
- await RedisHelper.HSetAsync(CacheCosmosPrefix + container.container.Id, entity.id, entity);
|
|
|
+ if (!RedisHelper.Exists(CacheCosmosPrefix + container.container.Id))
|
|
|
+ {
|
|
|
+ await RedisHelper.HSetAsync(CacheCosmosPrefix + container.container.Id, entity.id, entity);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await RedisHelper.HSetAsync(CacheCosmosPrefix + container.container.Id, entity.id, entity);
|
|
|
+ await RedisHelper.ExpireAsync(CacheCosmosPrefix + container.container.Id, timeoutSeconds);
|
|
|
+ }
|
|
|
}
|
|
|
return response.Resource;
|
|
|
}
|
|
@@ -714,6 +740,11 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
|
|
|
int pages = (int)Math.Ceiling((double)enyites.Count / pageSize);
|
|
|
CosmosModelInfo container = await InitializeCollection<T>();
|
|
|
+ bool flag = false;
|
|
|
+ if (RedisHelper.Exists(CacheCosmosPrefix + container.container.Id))
|
|
|
+ {
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
string pk = GetPartitionKey<T>();
|
|
|
Type type = typeof(T);
|
|
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
|
@@ -752,6 +783,10 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ if (container.cache && RedisHelper.Instance != null&&!flag)
|
|
|
+ {
|
|
|
+ await RedisHelper.ExpireAsync(CacheCosmosPrefix + container.container.Id, timeoutSeconds);
|
|
|
+ }
|
|
|
stopwatch.Stop();
|
|
|
return enyites;
|
|
|
}
|
|
@@ -764,7 +799,15 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
ItemResponse<T> response = await container.container.ReplaceItemAsync(entity, entity.id, new PartitionKey(o.ToString()));
|
|
|
if (container.cache && RedisHelper.Instance != null)
|
|
|
{
|
|
|
- await RedisHelper.HSetAsync(CacheCosmosPrefix + container.container.Id, entity.id, entity);
|
|
|
+ if (!RedisHelper.Exists(CacheCosmosPrefix + container.container.Id))
|
|
|
+ {
|
|
|
+ await RedisHelper.HSetAsync(CacheCosmosPrefix + container.container.Id, entity.id, entity);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await RedisHelper.HSetAsync(CacheCosmosPrefix + container.container.Id, entity.id, entity);
|
|
|
+ await RedisHelper.ExpireAsync(CacheCosmosPrefix + container.container.Id, timeoutSeconds);
|
|
|
+ }
|
|
|
}
|
|
|
return response.Resource;
|
|
|
}
|
|
@@ -786,6 +829,11 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
|
|
|
int pages = (int)Math.Ceiling((double)enyites.Count / pageSize);
|
|
|
CosmosModelInfo container = await InitializeCollection<T>();
|
|
|
+ bool flag = false;
|
|
|
+ if (RedisHelper.Exists(CacheCosmosPrefix + container.container.Id))
|
|
|
+ {
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
string pk = GetPartitionKey<T>();
|
|
|
Type type = typeof(T);
|
|
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
|
@@ -824,6 +872,10 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ if (container.cache && RedisHelper.Instance != null&&!flag)
|
|
|
+ {
|
|
|
+ await RedisHelper.ExpireAsync(CacheCosmosPrefix + container.container.Id, timeoutSeconds);
|
|
|
+ }
|
|
|
stopwatch.Stop();
|
|
|
return enyites;
|
|
|
}
|
|
@@ -839,8 +891,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
// CosmosClient?.Dispose();
|
|
|
// }
|
|
|
//}
|
|
|
-
|
|
|
- public async Task<T> FindById<T>(string id) where T : ID
|
|
|
+ private async Task<T> FindByIdAsSql<T>(string id) where T : ID
|
|
|
{
|
|
|
CosmosModelInfo container = await InitializeCollection<T>();
|
|
|
CosmosDbQuery cosmosDbQuery = new CosmosDbQuery
|
|
@@ -859,6 +910,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
return (await ResultsFromFeedIterator(feedIterator)).SingleOrDefault();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public async Task<T> FindByIdPk<T>(string id, string pk) where T : ID
|
|
|
{
|
|
|
CosmosModelInfo container = await InitializeCollection<T>();
|
|
@@ -866,22 +918,22 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
return response.Resource;
|
|
|
}
|
|
|
|
|
|
- public async Task<T> FindCacheShell<T>(string id) where T : ID
|
|
|
+ public async Task<T> FindById<T>(string id) where T : ID
|
|
|
{
|
|
|
CosmosModelInfo container = await InitializeCollection<T>();
|
|
|
if (container.cache && RedisHelper.Instance != null)
|
|
|
{
|
|
|
|
|
|
- return await RedisHelper.CacheShellAsync(CacheCosmosPrefix + container.container.Id , id , timeoutSeconds, () => { return FindById<T>(id); }) ;
|
|
|
+ return await RedisHelper.CacheShellAsync(CacheCosmosPrefix + container.container.Id , id , timeoutSeconds, () => { return FindByIdAsSql<T>(id); }) ;
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
- return await FindById<T>(id);
|
|
|
+ return await FindByIdAsSql<T>(id);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- public async Task<List<T>> FindListCacheShell<T>(List<string> ids) where T : ID
|
|
|
+ public async Task<List<T>> FindByIds<T>(List<string> ids) where T : ID
|
|
|
{
|
|
|
CosmosModelInfo container = await InitializeCollection<T>();
|
|
|
|
|
@@ -911,7 +963,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public async Task<dynamic> FindCacheShell(string CollectionName, string id)
|
|
|
+ public async Task<dynamic> FindById(string CollectionName, string id)
|
|
|
{
|
|
|
if (DocumentCollectionDict.TryGetValue(CollectionName, out CosmosModelInfo container))
|
|
|
{
|
|
@@ -932,7 +984,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public async Task<List<dynamic>> FindListCacheShell(string CollectionName, List<string> ids)
|
|
|
+ public async Task<List<dynamic>> FindByIds(string CollectionName, List<string> ids)
|
|
|
{
|
|
|
if (DocumentCollectionDict.TryGetValue(CollectionName, out CosmosModelInfo container))
|
|
|
{
|