Skip to content
This repository was archived by the owner on Jan 26, 2023. It is now read-only.

Commit eb02791

Browse files
committed
Added readme and gradle settings.
1 parent b8b85cd commit eb02791

File tree

6 files changed

+283
-1
lines changed

6 files changed

+283
-1
lines changed

README.md

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,152 @@
1-
# CacheLib [![Build Status](https://travis-ci.org/pcpl2/CacheLib.svg?branch=master)](https://travis-ci.org/pcpl2/CacheLib)
1+
# SimpleCache
2+
[![Build Status](https://travis-ci.org/pcpl2/CacheLib.svg?branch=master)](https://travis-ci.org/pcpl2/CacheLib)
3+
[![SimpleCache](https://api.bintray.com/packages/pcpl2/maven/simplecache/images/download.svg) ](https://bintray.com/pcpl2/maven/simplecache/_latestVersion)
4+
[![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=plastic)](https://android-arsenal.com/api?level=21)
5+
6+
A simple library for saving data in the cache and reading them.
7+
8+
# Setup
9+
The library is hosted on jcenter. To use it, add the following to your module level `build.gradle` file's dependencies:
10+
11+
```gradle
12+
dependencies {
13+
implementation 'com.github.pcpl2:simplecache:1.0.0'
14+
}
15+
```
16+
17+
# Basic usage
18+
19+
**To init instance of cache manager without filename:**
20+
21+
```kotlin
22+
val cacheManager = CacheManager.createInstance(appContext, null)
23+
```
24+
The `cacheManager` instance usage default cache file.
25+
26+
**To init instance of cache manager with filename:**
27+
28+
```kotlin
29+
val cacheManager = CacheManager.createInstance(appContext, "filesCache")
30+
```
31+
The `cacheManager` instance usage cache with file name `filesCache`.
32+
33+
34+
## Add elements to cache:
35+
The `add` function accepts 3 parameters: `key: Stirng, value: Any, lifetime: Long`.
36+
37+
The lifetime parameter is the lifetime in seconds and is optional, default setted to 0 (no lifetime).
38+
39+
**To add element to cache instance with set lifetime:**
40+
41+
```kotlin
42+
cacheManager.add("HelloWorldKey", "Hello World", 60)
43+
cacheManager.add("IntValueKey", 255, 30)
44+
cacheManager.add("BooleanKey", false, 60)
45+
cacheManager.add("FloatKey", 5.55, 60)
46+
```
47+
48+
**To add element to cache instance without set lifetime:**
49+
50+
```kotlin
51+
cacheManager.add("HelloWorldKey", "Hello World")
52+
cacheManager.add("IntValueKey", 255)
53+
cacheManager.add("BooleanKey", false)
54+
cacheManager.add("FloatKey", 5.55)
55+
```
56+
57+
## Getting element from cache:
58+
The `get` function accepts 3 parameters: `key: Stirng, checkExpired: Any, callback: (value: Any?, type: Class<*>?) -> Unit`.
59+
60+
The checkExpired parameter is optional, default setted as true.
61+
62+
In lambda callback `value` is a nullable any object and `type` is a nullable java Class.
63+
64+
**To get element from cache instance with lifetime check:**
65+
66+
```kotlin
67+
cacheManager.get("HelloWorldKey") { value, type ->
68+
System.out.println(value.toString())
69+
}
70+
71+
cacheManager.get("IntValueKey") { value, type ->
72+
System.out.println(value.toString())
73+
}
74+
75+
cacheManager.get("BooleanKey") { value, type ->
76+
System.out.println(value.toString())
77+
}
78+
79+
cacheManager.get("FloatKey") { value, type ->
80+
System.out.println(value.toString())
81+
}
82+
```
83+
84+
**To get element from cache instance without lifetime check:**
85+
86+
```kotlin
87+
cacheManager.get("HelloWorldKey", false) { value, type ->
88+
System.out.println(value.toString())
89+
}
90+
91+
cacheManager.get("IntValueKey", false) { value, type ->
92+
System.out.println(value.toString())
93+
}
94+
95+
cacheManager.get("BooleanKey", false) { value, type ->
96+
System.out.println(value.toString())
97+
}
98+
99+
cacheManager.get("FloatKey", false) { value, type ->
100+
System.out.println(value.toString())
101+
}
102+
```
103+
104+
## Remove element from cache
105+
The `remove` function accept 1 parameter: `key: Stirng`.
106+
107+
108+
**To remove element from cache instance:**
109+
```kotlin
110+
cacheManager.remove("FloatKey")
111+
```
112+
113+
## Clear cache instance
114+
The `removeAllElements` function cleans the entire cache.
115+
116+
**To clear cachce istance:**
117+
118+
```kotlin
119+
cacheManager.removeAllElements()
120+
```
121+
122+
## List of the cahce files.
123+
The `getListOfCacheFiles` function accept 1 parameter: `ctx: Context` and return list of exist cache files.
124+
125+
**To get cahce files:**
126+
127+
```kotlin
128+
CacheManager.getListOfCacheFiles(appContext)
129+
```
130+
131+
132+
133+
# Changelog
134+
Please see the [Changelog](https://github.com/pcpl2/CacheLib/wiki/Changelog) page to see what's recently changed.
135+
136+
137+
# License
138+
```
139+
Copyright 2018 Patryk Ławicki
140+
141+
Licensed under the Apache License, Version 2.0 (the "License");
142+
you may not use this file except in compliance with the License.
143+
You may obtain a copy of the License at
144+
145+
http://www.apache.org/licenses/LICENSE-2.0
146+
147+
Unless required by applicable law or agreed to in writing, software
148+
distributed under the License is distributed on an "AS IS" BASIS,
149+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
150+
See the License for the specific language governing permissions and
151+
limitations under the License.
152+
```

bintrayv1.gradle

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
apply plugin: 'com.jfrog.bintray'
2+
3+
version = libraryVersion
4+
5+
if (project.hasProperty("android")) { // Android libraries
6+
task sourcesJar(type: Jar) {
7+
classifier = 'sources'
8+
from android.sourceSets.main.java.srcDirs
9+
}
10+
11+
} else { // Java libraries
12+
task sourcesJar(type: Jar, dependsOn: classes) {
13+
classifier = 'sources'
14+
from sourceSets.main.allSource
15+
}
16+
}
17+
18+
artifacts {
19+
archives sourcesJar
20+
}
21+
22+
// Bintray
23+
if(project.rootProject.file('local.properties').exists()) {
24+
Properties properties = new Properties()
25+
properties.load(project.rootProject.file('local.properties').newDataInputStream())
26+
27+
bintray {
28+
user = properties.getProperty("bintray.user")
29+
key = properties.getProperty("bintray.apikey")
30+
31+
configurations = ['archives']
32+
pkg {
33+
repo = bintrayRepo
34+
name = bintrayName
35+
desc = libraryDescription
36+
websiteUrl = siteUrl
37+
vcsUrl = gitUrl
38+
licenses = allLicenses
39+
publish = true
40+
publicDownloadNumbers = true
41+
version {
42+
desc = libraryDescription
43+
gpg {
44+
sign = true //Determines whether to GPG sign the files. The default is false
45+
passphrase = properties.getProperty("bintray.gpg.password")
46+
//Optional. The passphrase for GPG signing'
47+
}
48+
}
49+
}
50+
}
51+
}

build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ buildscript {
99
dependencies {
1010
classpath 'com.android.tools.build:gradle:3.1.1'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
13+
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
14+
15+
configurations.all {
16+
resolutionStrategy {
17+
force "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
18+
}
19+
}
1220

1321
// NOTE: Do not place your application dependencies here; they belong
1422
// in the individual module build.gradle files

installv1.gradle

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apply plugin: 'com.github.dcendents.android-maven'
2+
3+
group = publishedGroupId // Maven Group ID for the artifact
4+
5+
install {
6+
repositories.mavenInstaller {
7+
// This generates POM.xml with proper parameters
8+
pom {
9+
project {
10+
packaging 'aar'
11+
groupId publishedGroupId
12+
artifactId artifact
13+
14+
// Add your description here
15+
name libraryName
16+
description libraryDescription
17+
url siteUrl
18+
19+
// Set your license
20+
licenses {
21+
license {
22+
name licenseName
23+
url licenseUrl
24+
}
25+
}
26+
developers {
27+
developer {
28+
id developerId
29+
name developerName
30+
email developerEmail
31+
}
32+
}
33+
scm {
34+
connection gitUrl
35+
developerConnection gitUrl
36+
url siteUrl
37+
38+
}
39+
}
40+
}
41+
}
42+
}

simplecache/build.gradle

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ android {
2727
}
2828
}
2929

30+
ext {
31+
bintrayRepo = 'maven'
32+
bintrayName = 'simplecache'
33+
34+
publishedGroupId = 'com.github.pcpl2'
35+
libraryName = 'SimpleCache'
36+
artifact = 'simplecache'
37+
38+
libraryDescription = 'A simple library for saving data in the cache and reading them.'
39+
40+
siteUrl = 'https://github.com/pcpl2/CacheLib'
41+
gitUrl = 'https://github.com/pcpl2/CacheLib.git'
42+
43+
libraryVersion = '1.0.0'
44+
45+
developerId = 'pcpl2'
46+
developerName = 'Patryk Ławicki'
47+
developerEmail = 'patryykk12@gmail.com'
48+
49+
licenseName = 'The Apache Software License, Version 2.0'
50+
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
51+
allLicenses = ["Apache-2.0"]
52+
}
53+
3054
dependencies {
3155
implementation fileTree(dir: 'libs', include: ['*.jar'])
3256

@@ -38,6 +62,10 @@ dependencies {
3862
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
3963
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4064
}
65+
4166
repositories {
4267
mavenCentral()
4368
}
69+
70+
apply from: '../installv1.gradle'
71+
apply from: '../bintrayv1.gradle'

simplecache/src/androidTest/java/com/github/pcpl2/simplecache/ExampleInstrumentedTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class ExampleInstrumentedTest {
8080
System.out.println(value.toString())
8181
}
8282

83+
cacheManager.remove("obj2")
84+
8385
System.out.println(CacheManager.getListOfCacheFiles(appContext).toString())
8486

8587
assertEquals("com.github.pcpl2.simplecache.test", appContext.packageName)

0 commit comments

Comments
 (0)