【发布时间】:2014-05-06 00:48:22
【问题描述】:
我目前在弄清楚如何使用 ImageResizer 插件以正确使用 SQL 和 DiskCache 插件时遇到问题。
我的命名策略如下:
/myimagetitle-4319560-100x100.jpg 被 IIS URL 重写模块重写为 /4319560.jpg?id=4319560&title=myimagetitle&height=100&width=100。
这按预期工作。
现在,为了找到图像的文件名,我需要使用 SQL 翻译 id。我创建了一个IVirtualImageProvider 插件,它实现了FileExists 和GetFile 方法。
public IVirtualFile GetFile(string virtualPath, NameValueCollection queryString)
{
var path = this.GetOriginalFilePath(queryString);
return new VirtualFileWrapper(new ProductPhotoVirtualFile(path));
}
public bool FileExists(string virtualPath, NameValueCollection queryString)
{
if (File.Exists(this.GetCachedFilePath(queryString)))
{
return true;
}
if (File.Exists(this.GetOriginalFilePath(queryString)))
{
return true;
}
return false;
}
private string GetCachedFilePath(NameValueCollection queryString)
{
// Get customized cache file path based on the query string
// "cache\4319\560\4319560_w_100_h_100.jpg"
}
private string GetOriginalFilePath(NameValueCollection queryString)
{
// Perform SQL lookup to translate the id from the query to a file name
}
我正在使用 DiskCache 插件来确保我的图像使用 IIS 等进行缓存。
不幸的是,FileExists 方法始终运行,对每个请求执行 SQL。
我想要达到的目标如下:
- 让 DiskCache 插件在
FileExists方法之前运行,这样如果文件被缓存,则跳过实际的 SQL 查找 - 处理缓存文件命名策略,以便其他工具在正确的文件夹中生成图像。
以上是否有可能和/或我做错了什么?
谢谢
【问题讨论】:
标签: imageresizer imageresizer-diskcache