必要なものはcache
シングルトンのようなものです。
すべてのDIを使用して、コントローラで次に
public interface IMyStuff{
string VeryImportantStringHere {get;}
}
public MyStuff :IMyStuff {
public string VeryImportantStringHere => {
var cached = HttpRuntime.Cache.Get(nameof(VeryImportantStringHere));
if(cached != null) // might need to store something else if you could have nulls in db
{
return cached ;
}
cached = .... // retrieved from DB however you do it - ADO.net, Linq2Sql, EF etc...
Cache.Insert(nameof(VeryImportantStringHere), cached , null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5));
}
}
、:
public controller MyController : Controller{
private IMyStuff _ms;
public MyController(IMyStuff ms)
{
_ms = ms;
}
[HttpGet]
public ActionResult Whatever(){
var cached = _ms.VeryImportantStringHere; // cached now has the value.
return View();
}
}
あなたはここに求めている正確に何
? – maccettura
私はアプリケーションを実行するたびにdbに格納されたデータを渡す方法を知る必要があります。それは私のコントローラの1つで、私はアプリケーションを再起動するたびに、すでに格納されているデータを渡す必要があります。 –
どこにデータを渡しますか? – Shyju