zoukankan      html  css  js  c++  java
  • Android 缓存策略demo

    packageinstallerpermissionmodelPermissionApps.java

        /**
         * Class used to reduce the number of calls to the package manager.
         * This caches app information so it should only be used across parallel PermissionApps
         * instances, and should not be retained across UI refresh.
         */
        public static class PmCache {
            private final SparseArray<List<PackageInfo>> mPackageInfoCache = new SparseArray<>();
            private final PackageManager mPm;
    
            public PmCache(PackageManager pm) {
                mPm = pm;
            }
    
            public synchronized List<PackageInfo> getPackages(int userId) {
                List<PackageInfo> ret = mPackageInfoCache.get(userId);
                if (ret == null) {
                    ret = mPm.getInstalledPackagesAsUser(PackageManager.GET_PERMISSIONS, userId);
                    mPackageInfoCache.put(userId, ret);
                }
                return ret;
            }
        }
    private final PmCache mCache;
    
    List<PackageInfo> apps = mCache != null ? mCache.getPackages(user.getIdentifier())
                        : mPm.getInstalledPackagesAsUser(PackageManager.GET_PERMISSIONS,
                                user.getIdentifier());
    /**
    * Class used to reduce the number of calls to the package manager.
    * This caches app information so it should only be used across parallel PermissionApps
    * instances, and should not be retained across UI refresh.
    */
    public static class PmCache {
    private final SparseArray<List<PackageInfo>> mPackageInfoCache = new SparseArray<>();
    private final PackageManager mPm;

    public PmCache(PackageManager pm) {
    mPm = pm;
    }

    public synchronized List<PackageInfo> getPackages(int userId) {
    List<PackageInfo> ret = mPackageInfoCache.get(userId);
    if (ret == null) {
    ret = mPm.getInstalledPackagesAsUser(PackageManager.GET_PERMISSIONS, userId);
    mPackageInfoCache.put(userId, ret);
    }
    return ret;
    }
    }
  • 相关阅读:
    mysql 常用函数
    JSP 分页代码
    day15(Mysql学习)
    day14(编码实战-用户登录注册)
    Bootstrap第3天
    Bootstrap第2天
    Bootstrap 第一天
    day13(JSTL和自定义标签&MVC模型&javaweb三层框架)
    label 对齐
    Alert提示框之后跳转指定页面
  • 原文地址:https://www.cnblogs.com/onelikeone/p/9312208.html
Copyright © 2011-2022 走看看