You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1021 B

2 years ago
  1. using System;
  2. namespace SqlSugar
  3. {
  4. internal class CacheSchemeMain
  5. {
  6. public static T GetOrCreate<T>(ICacheService cacheService, QueryBuilder queryBuilder, Func<T> getData, int cacheDurationInSeconds, SqlSugarClient context)
  7. {
  8. var key = CacheKeyBuider.GetKey(context, queryBuilder);
  9. var keyString = key.ToString();
  10. var result = cacheService.GetOrCreate(keyString, getData, cacheDurationInSeconds);
  11. return result;
  12. }
  13. public static void RemoveCache(ICacheService cacheService, string tableName)
  14. {
  15. var keys = cacheService.GetAllKey<string>();
  16. if (keys.HasValue())
  17. {
  18. foreach (var item in keys)
  19. {
  20. if (item.ToLower().Contains(UtilConstants.Dot + tableName.ToLower() + UtilConstants.Dot))
  21. {
  22. cacheService.Remove<string>(item);
  23. }
  24. }
  25. }
  26. }
  27. }
  28. }