ユーザーがデータベースを更新するたびにシングルトンインスタンスを強制的にリセットする方法はありますか?C#でシングルトンインスタンスをリセットする方法は?
public class Example{
private Dictionary<int, string> _list;
private Example(){
_list = new Dictionary<int, string>();
//Get data from database here and add the data to _list
}
private class Nested{
static Nested(){}
internal static readonly Example Instance = new Example();
}
public static Dictionary<int, string> GetExample(){
return Nested.Instance._list
}
}
したがって、データベースが更新されたら_listをリセットしますか?
ありがとうございます!
データベースが更新されたことをどのように知っていますか?ネストされたクラスの有用性は何ですか? – RQDQ
キャッシュを使用し、更新時に競合状態を保護する必要があるデータのコンシューマに応じてSQL依存性の有効期限を設定します。 –