c# - 如何在类中缓存查询结果,然后根据 C# 方法中传递的参数重用它进行搜索?
问题描述
我正在尝试在 ASP.NET MVC Web 应用程序中实现搜索属性功能,其中页面具有体验列表,并且每个体验都有分配给它的唯一 ID 并具有属性列表。当用户单击一个体验时,它将显示与该体验相关的属性。现在,当用户单击另一个体验时,它将同时获取 id 并返回公共属性。我有一个缓存数据库结果并存储它的类。
public class GetExperienceResponse
{
public string Experienceid { get; set; }
public List<string> Properties { get; set; }
//Example: Expereienceid="E1", Properties="P1,P2,P3"
Experienceid="E2", Properties="P3,P4,P5"
}
public static List<GetExperienceAmenityResponse> GetExperience()
{
//returns experience and related properties here and cached it
}
我根据点击的经验用于搜索属性的方法是:
public ActionResult ExperienceSearch(string id)
{
List<GetExperienceResponse> Experiences = new List<GetExperienceResponse>();
Experiences = GetExperience(); //Populate the Experience result list
//logic for searching. When Click on Experience1, it will pass id "E1" and should display Properties "P1", "P2" and "P3". When Click on both Experience it should display common property which is "P3" here (Intersection of Experience 1 and Experience 2).
return View();
}
实现此搜索的最佳方法是什么?我可以对返回的结果使用 LINQ 查询吗?我将不胜感激。非常感谢您!
解决方案
个人体验可以有唯一的 Cachekey,公共属性可以有共同的缓存键(Experienceid1 &Experienceid2 的hashkey)。
推荐阅读
- c# - 带有索引参数的 Blazor/razor onclick 事件
- php - 无法在php中打印json数组值
- keras - 如何调整我的数据集(64,64)中的图像大小以适合 VGG16(224,224)
- jenkins - 如果加载的 groovy 脚本提供了特定的闭包,请检查 Jenkins 管道
- angular - 添加角度材料时,如果没有“新”,则无法调用类构造函数平台
- python - 如何在 kivy FileChooser Python 中访问所有硬盘
- linux - shell脚本网络构建错误:未找到,:文件名太长
- javascript - FormData 没有得到任何响应
- python - 如何在 debian 10 上安装 python3.8?
- java - 有没有一种方法可以使用 Java 编程从 GIT 远程存储库中读取所有文件?