얼마나 많은 파일이 있고 얼마나 자주 읽어야하는지에 따라 asp.net 캐시 에 동적으로로드하는 것이 좋으며 일부 유형의 만료 또는 캐시가 있어야합니다.
파일 액세스 및 캐싱 구현을 마무리하기위한 몇 가지 유형의 클래스를 작성하십시오. 이 코드는 작동하지만 그대로 사용하지 마십시오. 내가 말하는 것에 대한 아이디어를 제공하는 것입니다. 개선을 위해 모든 의견을 남기지 마십시오.
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;
}
}
}
캐시 만료 기간을 고려하여 데이터에 가장 적합한 것이 무엇인지 확인하십시오. 당신은 또한 당신이 만료되면 메모리 풋 프린트가 커지지 않도록 캐시 된 파일의 최대 개수를 허용하는 몇 가지 유형의 최대 검사를 구현할 수 있습니다. 총 파일 수와 파일 크기를보고 필요에 가장 적합한 파일을 찾아야합니다.