缓存 SHA1 摘要结果?
我根据原始文件名及其版本的摘要存储文件的多个版本,如下所示:
$filename = sha1($original . ':' . $version);
是否值得将摘要($filename)作为键/值对缓存在memcache中(键是原始+版本并值sha1哈希值),或者足够快地生成摘要(对于高流量的php web)应用程序)?
谢谢,
乔纳森
I'm storing several versions of a file based on a digest of the original filename and its version, like this:
$filename = sha1($original . ':' . $version);
Would it be worth it to cache the digest ($filename) in memcache as a key/value pair (the key being the original + version and value the sha1 hash), or is generating the digest quick enough (for a high traffic php web app)?
Thanks,
Johnathan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你最好不要缓存哈希值。在我的笔记本电脑(相当快的 Core 2 Duo)上计算短文件名的 100,000 个哈希大约需要 1/2 秒:
总计:00:00:00.5186110
每个哈希时间:00:00:00.0000014
You're much better off not caching the hashes. Computing 100,000 hashes on short filenames takes around 1/2 a second on my laptop (a reasonably fast Core 2 Duo):
Total: 00:00:00.5186110
Time per hash: 00:00:00.0000014
哈希非常快,特别是对于小输入(例如文件的名称和版本)。
现在,如果您对文件本身进行哈希处理,并且它们非常大,那将是一个不同的故事(仅仅是因为从磁盘读取整个文件需要很长时间)
Hashes are extremely fast, especially for small inputs (such as the name and version of a file).
Now, if you were hashing the files themselves, and they were very large, that would be a different story (simply because it would take so long to read the entire file from off the disk)