Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代码优化建议 #43

Open
mosentest opened this issue Jun 23, 2018 · 1 comment
Open

代码优化建议 #43

mosentest opened this issue Jun 23, 2018 · 1 comment

Comments

@mosentest
Copy link

mosentest commented Jun 23, 2018

`

//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
你都不合并人家代码,我只能这样改了

@MartinLi2015
Copy link

你这么改,全局只有一个Acahe,那么cacheDir就无法修改了。会产生三个问题
1、用户自定义存储的目录失效
2、只存在一个目录,一旦存储内容多,50m上限达到,容易造成文件频繁删除
3、lastUsageDates的map初次缓存特别大,对于内存属于浪费

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants