あなたが持っているファイルの数や読んでいる頻度によっては、asp.netキャッシュASに動的にロードすることと、ある種の有効期限やキャッシュを持つことをお勧めします。
ファイルアクセスとキャッシングimplementatonをラップするためのいくつかのタイプのクラスを作成します。このコードはおそらく動作しますが、それをそのまま使用することはありません。私が話していることのアイデアを伝えるだけです。改善のためのすべてのコメントはありません。
public static class StaticFiles
{
public static string GetFile(string file)
{
// Note filename is the key
if (Cache[file] != null)
{
// Return the cached data, this will be fast.
return Cache[file].ToString();
}
else
{
// Make sure you do some exception checking/validation here for the
// file data and don't hard code the path and make it relative assuming
// it is in your application directory
// Do you file access and store it with some type of expiry
string output = System.IO.File.ReadAllText(string.Format("c:\path\to\{0}", file));
Cache[file] = output;
return output;
}
}
}
キャッシュが期限切れであるとみなし、データに最も適したものを確認してください。いくつかのタイプのmaxチェックを実装して、キャッシュされたファイルの最大数を許可して、有効期限が長い場合はメモリの足跡が大きくならないようにすることもできます。あなたは本当にファイルの総数とそのサイズを見て、あなたのニーズに最も適したものを見つけ出す必要があります。