Code Monkey home page Code Monkey logo

here's Introduction

Here

Here 是基于腾讯MMKV实现便于Android使用的Key-Value存储库。MMKV自身非常高效,其内部使用mmap同步内存数据到文件,使用protobuf对数据进行encode/decode,读写性能远优于SharedPreference,在Android上完全可以替代SharedPreference使用。我们基于这些特性,进行了上层的封装与拓展,使其在Android上使用更加高效便利。性能请参考MMKV android benchmark

Baseline Performance

Usage:

1. 基本用法

// 在使用前或在Application进行初始化
Here.init(this)
// 在需要存储值的地方直接调用Here.put(key, value)方法
Here.put("text", 100)
// 取值
Here.getInt("text")
// or
Here.getInt("text", -1)

2. 基于bucket进行存储

bucket相当于命名空间,不同的bucket下同名的key并不冲突

// init, 全局初始化一次即可,不需要每次都初始化
Here.init(this)
	
Here.bucket("bucket_name").put("test", 10)
													.put("test2", "value2")
													
val value = Here.bucket("bucket_name").getInt("test")

// 可以使用kotlin lambda设置
Here.bucket("bucket_name"){
	put("key1", "value1")
	put("key2", "value2")
}	

3. 删除数据

// 该方法只会删除全局的key-value, 不会删除bucket上的数据
Here.clearAll()

// clearAll, 只会删除bucket_name上的数据
Here.bucket("bucket_name").clearAll()
	
// 删除某个值
Here.bucket("bucket_name").removeValueForKey("key")
	

4. 支持的存储类型

  • List<E: Parcelable>
  • E: Parcelable
  • Boolean
  • Int
  • Long
  • Float
  • Double
  • String
  • ByteArray
  • Set<String>

here's People

Contributors

ansnail avatar derlio avatar liu88122 avatar real1024 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.