public CachedData Get(string key)
{
var path = Path.Combine(basePath, EscapeKey(key));
if (File.Exists(path) == false)
return null;
try
{
using (var file = File.OpenRead(path))
{
return (CachedData)new BinaryFormatter().Deserialize(file);
}
}
catch (SerializationException)
{
// this usually happen as a result of versioning issues
// since this is a cache, we can just delete the file and move on
File.Delete(path);
return null;
}
}