Why Volley DiskBasedCache splicing without direct access to the cache file name

↘锁芯ラ 提交于 2019-12-30 10:47:11

问题


/**
 * Creates a pseudo-unique filename for the specified cache key.
 *
 * @param key The key to generate a file name for.
 * @return A pseudo-unique filename.
 */
private String getFilenameForKey(String key) {
    int firstHalfLength = key.length() / 2;
    String localFilename = String.valueOf(key.substring(0, firstHalfLength).hashCode());
    localFilename += String.valueOf(key.substring(firstHalfLength).hashCode());
    return localFilename;
}

This code from Google Volley DiskBasedCache.
Why splicing without direct access.
e.g:

return String.valueOf(key.hashCode());

回答1:


I'm not one of the developers, but I believe their train of thought was this: Our keys are URLs. A lot of the times, different URLs (typically of the same site) share a good number of characters. That's why the key hashing is performed on the first half of the key and on the second half separately - to create more variance in the file names. Hash isn't super reliable in Java.



来源:https://stackoverflow.com/questions/34984302/why-volley-diskbasedcache-splicing-without-direct-access-to-the-cache-file-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!