Skip to content

代码优化建议 #43

@mosentest

Description

@mosentest

`

//private static Map<String, ACache> mInstanceMap = Collections.synchronizedMap(new
HashMap<String, ACache>());
private static ACache instance = null;

/**
 * 个人觉得没必要用map来缓存实例,一个就够用了
 * @param cacheDir
 * @param max_zise
 * @param max_count
 * @return
 */
public  static ACache get(File cacheDir, long max_zise, int max_count) {
    if (instance == null) {
        synchronized (ACache.class) {
            //ACache manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
            if (instance == null) {
                instance = new ACache(cacheDir, max_zise, max_count);
                //mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
            }
        }
    }
    return instance;
}

    /**
     * hashCode发生碰撞怎么办,我建议用base64
     * @param key
     * @return
     */
    private File newFile(String key) {
        //return new File(cacheDir, key.hashCode() + "");
        return new File(cacheDir, Base64.encodeToString(key.getBytes(), Base64.NO_WRAP) + "");
    }

`
我改过的版本在这里:
https://github.com/moz1q1/WalleLibrary/tree/master/library_utils/src/main/java/org/wall/mo/utils/cache
你都不合并人家代码,我只能这样改了

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions