SettingsProvider 它SettingsCache
转载请注明出处:http://blog.csdn.net/droyon/article/details/35558437
SettingsCache,如指出,SettingsProvider缓冲。这将缓冲所有当前请求访问key值及其value。此缓冲区处在内存中,读取效率较高。
SettingsProvider支持多用户概念,每一个用户都有至少三张表(System、Secure)。每一张表都存在一个SettingsCache。
1、在手机启动时,会将SettingsProvider相应的数据库中的数据表的内容缓冲进来。
private void fullyPopulateCache(DatabaseHelper dbHelper, String table, SettingsCache cache) {
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor c = db.query(
table,
new String[] { Settings.NameValueTable.NAME, Settings.NameValueTable.VALUE },
null, null, null, null, null,
"" + (MAX_CACHE_ENTRIES + 1) /* limit */);
try {
synchronized (cache) {
cache.evictAll();
cache.setFullyMatchesDisk(true); // optimistic
int rows = 0;
while (c.moveToNext()) {
rows++;
String name = c.getString(0);
String value = c.getString(1);
cache.populate(name, value);
}
if (rows > MAX_CACHE_ENTRIES) {
// Somewhat redundant, as removeEldestEntry() will
// have already done this, but to be explicit:
cache.setFullyMatchesDisk(false);
Log.d(TAG, "row count exceeds max cache entries for table " + table);
}
if (LOCAL_LOGV) Log.d(TAG, "cache for settings table '" + table
+ "' rows=" + rows + "; fullycached=" + cache.fullyMatchesDisk());
}
} finally {
c.close();
}
}
2、SettingsCache extends LruCache<String, Bundle>
/**
* In-memory LRU Cache of system and secure settings, along with
* associated helper functions to keep cache coherent with the
* database.
* 在内存中缓存System,Secure的设置项,以及相关功能方法来保证和数据库的一致性。 */
private boolean mCacheFullyMatchesDisk = false; // has the whole database slurped. 标记内存LRU缓冲是否清空了整个数据库
cache.evictAll();//remove全部元素,回调entryRemoved(true,key。value)
3、putIfAbsent方法
/**
* Atomic cache population, conditional on size of value and if
* we lost a race.
*
* @returns a Bundle to send back to the client from call(), even
* if we lost the race.
*/
public Bundle putIfAbsent(String key, String value) {
Bundle bundle = (value == null) ? NULL_SETTING : Bundle.forPair("value", value);
if (value == null || value.length() <= MAX_CACHE_ENTRY_SIZE) {//假设value为null,或者value的长度小于500字符
synchronized (this) {
if (get(key) == null) {
put(key, bundle);//bundle可能:NULL_SETTINGS、Bundle.forPair("value", value)
}
}
}//【value不为null,且value的长度大于500,直接返回bundle,bundle为Bundle.forPair("value", value)】
return bundle;
}
4、populate(填充)
/**
* Populates a key in a given (possibly-null) cache.
* 填充cache中的keyword
*/
public static void populate(SettingsCache cache, ContentValues contentValues) {
if (cache == null) {
return;
}
String name = contentValues.getAsString(Settings.NameValueTable.NAME);
if (name == null) {
Log.w(TAG, "null name populating settings cache.");
return;
}
String value = contentValues.getAsString(Settings.NameValueTable.VALUE);
cache.populate(name, value);
}
5、检查反复
/**
* For suppressing duplicate/redundant settings inserts early,
* checking our cache first (but without faulting it in),
* before going to sqlite with the mutation.
* 在插入前,检查反复。 在使用sqlite前。先检查cache
* 是否为反复的值。 */
public static boolean isRedundantSetValue(SettingsCache cache, String name, String value) {
if (cache == null) return false;
synchronized (cache) {
Bundle bundle = cache.get(name);
if (bundle == null) return false;
String oldValue = bundle.getPairValue();
if (oldValue == null && value == null) return true;
if ((oldValue == null) != (value == null)) return false;//奇妙代码
return oldValue.equals(value);
}
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
SettingsProvider 它SettingsCache的更多相关文章
- Winform开发框架之参数配置管理功能实现-基于SettingsProvider.net的构建
在较早时期,我写过一篇文章<结合Control.FirefoxDialog控件,构造优秀的参数配置管理模块>,介绍过在我的Winform框架基础上集成的参数配置模块功能,但是参数模块的配置 ...
- SettingsProvider该CRUD
转载请注明出处:http://blog.csdn.net/droyon/article/details/35558697 什么时候delete要么update时间.需要清空缓存并重新加载数据. 1.i ...
- Android默认输入法语言的修改以及SettingsProvider作用
Android源码中默认的有三种输入法:英文,中文,日文.对应的工程代码路径为:<android_root>/packages/inputmethods/LatinIME/<andr ...
- External Configuration Store Pattern 外部配置存储模式
Move configuration information out of the application deployment package to a centralized location. ...
- c#面试题汇总
下面的参考解答只是帮助大家理解,不用背,面试题.笔试题千变万化,不要梦想着把题覆盖了,下面的题是供大家查漏补缺用的,真正的把这些题搞懂了,才能“以不变应万变”.回答问题的时候能联系做过项目的例子是最好 ...
- .NET工程师面试宝典
.Net工程师面试笔试宝典 传智播客.Net培训班内部资料 这套面试笔试宝典是传智播客在多年的教学和学生就业指导过程中积累下来的宝贵资料,大部分来自于学员从面试现场带过来的真实笔试面试题,覆盖了主流的 ...
- 传智播客DotNet面试题
技术类面试.笔试题汇总(整理者:杨中科,部分内容从互联网中整理而来) 注:标明*的问题属于选择性掌握的内容,能掌握更好,没掌握也没关系. 下面的参考解答只是帮助大家理解,不用背,面试题.笔试题千变万化 ...
- 【转】VS2010安装后出现无法使用帮助的解决方案
安装完VS2010后 再安装MSDN 打开“Help Library 管理器 - Microsoft Help 查看器 1.0” 提示“请为本地内容选择位置” 默认的位置是在“C:/Documents ...
- Interview
下面的题是供大家查漏补缺用的,真正的把这些题搞懂了,才能"以不变应万变". 回答问题的时候能联系做过项目的例子是最好的,有的问题后面我已经补充联系到项目中的对应的案例了. 1.简述 ...
随机推荐
- ajax j跨域请求sonp
需求 遇到的问题 解决方案 需求 如今,该项目需要获得数据访问外部链接.它是跨域.使用ajax 直提示: 遇到的问题 1. 怎样使用ajax 跨域请求数据 2. 能不能post请求 解决的方法 经过网 ...
- 解析DBR操作系统引导记录数据
理解文件系统.你必须要熟悉DBR,下面我们就来看看文件系统解析DBR数据. Dos Boot Record(DBR)操作系统引导记录是由操作系统的格式化程序建立的.在文件系统驱动操作不论什么一个磁盘卷 ...
- Xampp mysql无法启动的解决方案(转)
如果出现mysql 无法启动表明在安装xampp 前已经安装了mysql,造成mysql服务无法启动. [mysql] MySQL Service detected with wrong path23 ...
- 白板编程浅谈——Why, What, How(转)
原文链接:http://lucida.me/blog/whiteboard-coding-demystified/ 这篇文章节选自我正在撰写的一本关于应届生面试求职的书籍,欢迎在评论或微博(@peng ...
- 我只是不甘心-------Day51
回放假回家一天,完全断网,天气也很给力配合.水蓝色的天空.白云,抬眼,我没有看到刺目的光芒,但仍眼眼睛刺痛.已经缩小眼,我试图打开眼睛,就像眼泪都流出来了,它不会擦到沙,这是很多其他的没地方. 哥哥去 ...
- Directx11学习笔记【九】 【转】 3D渲染管线
原文地址:http://blog.csdn.net/bonchoix/article/details/8298116 3D图形学研究的基本内容,即给定场景的描述,包括各个物体的材质.纹理.坐标等,照相 ...
- 集差集 哈希表 比较数据库的照片和server画面上,将server垃圾上的图片删除
SSH 骨架code: public String deleRubbishAd(){ int deleADcount = 0; rubbishADtp = configDao.rubbishADtp( ...
- H. 硬币的水问题II
H. 硬币水题II Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: ...
- AspUpload组件的安装及使用方法介绍
http://soft.huweishen.com/soft/47.html AspUpload对ASP编程人员来说要实现ASP网站文件上传功能它是首选.本文就为大家介绍一下AspUpload组件的安 ...
- c++内存泄漏处理(积累)
写c++程序时,常常会出现内存泄漏的问题,这里从网上找了一种非常麻烦的方法:假设想找到每一个cpp文件的内存泄漏,都必须在每一个cpp加上例如以下代码: #include <crtdbg.h&g ...