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

Commit

Permalink
Added readme and gradle settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcpl2 committed Apr 22, 2018
1 parent b8b85cd commit eb02791
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 1 deletion.
153 changes: 152 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,152 @@
# CacheLib [![Build Status](https://travis-ci.org/pcpl2/CacheLib.svg?branch=master)](https://travis-ci.org/pcpl2/CacheLib)
# SimpleCache
[![Build Status](https://travis-ci.org/pcpl2/CacheLib.svg?branch=master)](https://travis-ci.org/pcpl2/CacheLib)
[![SimpleCache](https://api.bintray.com/packages/pcpl2/maven/simplecache/images/download.svg) ](https://bintray.com/pcpl2/maven/simplecache/_latestVersion)
[![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=plastic)](https://android-arsenal.com/api?level=21)

A simple library for saving data in the cache and reading them.

# Setup
The library is hosted on jcenter. To use it, add the following to your module level `build.gradle` file's dependencies:

```gradle
dependencies {
implementation 'com.github.pcpl2:simplecache:1.0.0'
}
```

# Basic usage

**To init instance of cache manager without filename:**

```kotlin
val cacheManager = CacheManager.createInstance(appContext, null)
```
The `cacheManager` instance usage default cache file.

**To init instance of cache manager with filename:**

```kotlin
val cacheManager = CacheManager.createInstance(appContext, "filesCache")
```
The `cacheManager` instance usage cache with file name `filesCache`.


## Add elements to cache:
The `add` function accepts 3 parameters: `key: Stirng, value: Any, lifetime: Long`.

The lifetime parameter is the lifetime in seconds and is optional, default setted to 0 (no lifetime).

**To add element to cache instance with set lifetime:**

```kotlin
cacheManager.add("HelloWorldKey", "Hello World", 60)
cacheManager.add("IntValueKey", 255, 30)
cacheManager.add("BooleanKey", false, 60)
cacheManager.add("FloatKey", 5.55, 60)
```

**To add element to cache instance without set lifetime:**

```kotlin
cacheManager.add("HelloWorldKey", "Hello World")
cacheManager.add("IntValueKey", 255)
cacheManager.add("BooleanKey", false)
cacheManager.add("FloatKey", 5.55)
```

## Getting element from cache:
The `get` function accepts 3 parameters: `key: Stirng, checkExpired: Any, callback: (value: Any?, type: Class<*>?) -> Unit`.

The checkExpired parameter is optional, default setted as true.

In lambda callback `value` is a nullable any object and `type` is a nullable java Class.

**To get element from cache instance with lifetime check:**

```kotlin
cacheManager.get("HelloWorldKey") { value, type ->
System.out.println(value.toString())
}

cacheManager.get("IntValueKey") { value, type ->
System.out.println(value.toString())
}

cacheManager.get("BooleanKey") { value, type ->
System.out.println(value.toString())
}

cacheManager.get("FloatKey") { value, type ->
System.out.println(value.toString())
}
```

**To get element from cache instance without lifetime check:**

```kotlin
cacheManager.get("HelloWorldKey", false) { value, type ->
System.out.println(value.toString())
}

cacheManager.get("IntValueKey", false) { value, type ->
System.out.println(value.toString())
}

cacheManager.get("BooleanKey", false) { value, type ->
System.out.println(value.toString())
}

cacheManager.get("FloatKey", false) { value, type ->
System.out.println(value.toString())
}
```

## Remove element from cache
The `remove` function accept 1 parameter: `key: Stirng`.


**To remove element from cache instance:**
```kotlin
cacheManager.remove("FloatKey")
```

## Clear cache instance
The `removeAllElements` function cleans the entire cache.

**To clear cachce istance:**

```kotlin
cacheManager.removeAllElements()
```

## List of the cahce files.
The `getListOfCacheFiles` function accept 1 parameter: `ctx: Context` and return list of exist cache files.

**To get cahce files:**

```kotlin
CacheManager.getListOfCacheFiles(appContext)
```



# Changelog
Please see the [Changelog](https://github.com/pcpl2/CacheLib/wiki/Changelog) page to see what's recently changed.


# License
```
Copyright 2018 Patryk Ławicki
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
51 changes: 51 additions & 0 deletions bintrayv1.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apply plugin: 'com.jfrog.bintray'

version = libraryVersion

if (project.hasProperty("android")) { // Android libraries
task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}

} else { // Java libraries
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
}

artifacts {
archives sourcesJar
}

// Bintray
if(project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")

configurations = ['archives']
pkg {
repo = bintrayRepo
name = bintrayName
desc = libraryDescription
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = allLicenses
publish = true
publicDownloadNumbers = true
version {
desc = libraryDescription
gpg {
sign = true //Determines whether to GPG sign the files. The default is false
passphrase = properties.getProperty("bintray.gpg.password")
//Optional. The passphrase for GPG signing'
}
}
}
}
}
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

configurations.all {
resolutionStrategy {
force "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
}

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
42 changes: 42 additions & 0 deletions installv1.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apply plugin: 'com.github.dcendents.android-maven'

group = publishedGroupId // Maven Group ID for the artifact

install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar'
groupId publishedGroupId
artifactId artifact

// Add your description here
name libraryName
description libraryDescription
url siteUrl

// Set your license
licenses {
license {
name licenseName
url licenseUrl
}
}
developers {
developer {
id developerId
name developerName
email developerEmail
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl

}
}
}
}
}
28 changes: 28 additions & 0 deletions simplecache/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ android {
}
}

ext {
bintrayRepo = 'maven'
bintrayName = 'simplecache'

publishedGroupId = 'com.github.pcpl2'
libraryName = 'SimpleCache'
artifact = 'simplecache'

libraryDescription = 'A simple library for saving data in the cache and reading them.'

siteUrl = 'https://github.com/pcpl2/CacheLib'
gitUrl = 'https://github.com/pcpl2/CacheLib.git'

libraryVersion = '1.0.0'

developerId = 'pcpl2'
developerName = 'Patryk Ławicki'
developerEmail = 'patryykk12@gmail.com'

licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

Expand All @@ -38,6 +62,10 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

repositories {
mavenCentral()
}

apply from: '../installv1.gradle'
apply from: '../bintrayv1.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class ExampleInstrumentedTest {
System.out.println(value.toString())
}

cacheManager.remove("obj2")

System.out.println(CacheManager.getListOfCacheFiles(appContext).toString())

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

0 comments on commit eb02791

Please sign in to comment.