{"id":26471126,"url":"https://github.com/lekhana3003/simplcache","last_synced_at":"2026-04-13T13:02:05.598Z","repository":{"id":38398174,"uuid":"274475716","full_name":"lekhana3003/SimplCache","owner":"lekhana3003","description":"An Easy Java Cache Library","archived":false,"fork":false,"pushed_at":"2022-06-06T00:40:45.000Z","size":410,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-19T20:53:22.566Z","etag":null,"topics":["cache","cache-database","cache-storage","cachemanager","database","eviction","eviction-policies","github","java","library","redis"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lekhana3003.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-23T18:07:11.000Z","updated_at":"2024-04-10T17:27:28.000Z","dependencies_parsed_at":"2022-08-26T20:12:28.195Z","dependency_job_id":null,"html_url":"https://github.com/lekhana3003/SimplCache","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/lekhana3003/SimplCache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lekhana3003%2FSimplCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lekhana3003%2FSimplCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lekhana3003%2FSimplCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lekhana3003%2FSimplCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lekhana3003","download_url":"https://codeload.github.com/lekhana3003/SimplCache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lekhana3003%2FSimplCache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31753551,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T09:16:15.125Z","status":"ssl_error","status_checked_at":"2026-04-13T09:16:05.023Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","cache-database","cache-storage","cachemanager","database","eviction","eviction-policies","github","java","library","redis"],"created_at":"2025-03-19T20:53:24.486Z","updated_at":"2026-04-13T13:02:05.582Z","avatar_url":"https://github.com/lekhana3003.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimplCache - An Easy Java Cache Library\n[![Maven Central](https://img.shields.io/maven-central/v/com.github.lekhana3003/SimplCache.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.lekhana3003%22%20AND%20a:%22SimplCache%22) [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0)\u003cbr\u003e\nSimplCache library can be used to implement cache instantly.\u003cbr/\u003e\nThe library takes implementations of two databases,\n* Cache Database\n* Persistent Database\u003cbr\u003e\n\nAfter which it provides all the features of cache seamlessly.\u003cbr\u003e\n\n## Table of Contents\n- [1. Features](#1-features)\n- [2. Setup](#2-setup)\n- [3. Usage](#3-usage)\n  * [3.1 Getting Started](#31-getting-started)\n  * [3.2 Setting Cache Properties](#32-setting-cache-properties)\n    + [3.2.1 Eviction Policy](#321-eviction-policy)\n    + [3.2.2 Cache Type properties](#322-cache-type-properties)\n    + [3.2.3 Cache Memory Types](#323-cache-memory-types)\n  * [3.3 Put Method](#33-put-method)\n  * [3.4 Get Method](#34-get-method)\n  * [3.5 Write-Back Method](#35-write-back-method)\n  * [3.6 Flush Method](#36-flush-method)\n  * [3.7 Close Method](#37-close-method)\n  * [3.8 Save State](#38-save-state)\n      - [Saving:](#saving-)\n      - [Building from save state:](#building-from-save-state-)\n- [4. Example](#4-example)\n- [5. License](#5-license)\n- [6. Author](#6-author)\n\n\n\n## 1. Features\n\nThe features provided by the library are,\n* Easy Implementation\u003cbr\u003e\nTo implement the cache the user has to implement only two interfaces (i.e \u003cb\u003eCacheDB\u003c/b\u003e and \u003cb\u003ePersistentDB\u003c/b\u003e).\nThese databases can be of any type.(Relational or Non-Relational database) and rest is taken care by the SimplCache.\n* Least Recently Used (LRU) Eviction\u003cbr\u003e\nLeast recently used cache object is evicted when cache reaches maximum limit.\n* Timed Eviction\u003cbr\u003e\nObjects are removed from the cache after the given interval time.\n* Write Through\u003cbr\u003e\nThe data is simultaneously updated to cache and persistent database.\n* Write Back\u003cbr\u003e\nThe data is updated only in the cache and updated into the persistent database in later time.\n* Automated Write Back\u003cbr\u003e\nThe data in the cache is regularly updated in the persistent database at the interval given by the user.\n* Cache Size\u003cbr\u003e\nThe cache size can be given either as count of the objects to be stored in cache or the actual memory occupied by the objects in the cache (i.e KiloBytes).\n* Save State\u003cbr\u003e\nSave the state of the cache at any point in time by calling a simple method and rebuild the same cache at any point by calling simple method.\n\n## 2. Setup\nMaven:\n```\n \u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.lekhana3003\u003c/groupId\u003e\n    \u003cartifactId\u003eSimplCache\u003c/artifactId\u003e\n    \u003cversion\u003e1.2.x\u003c/version\u003e\n  \u003c/dependency\u003e\n```\nGradle:\n```\ndependencies {\n   implementation 'com.github.lekhana3003:SimplCache:1.2.x'\n}\n```                                                       \n\u003ctable\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cb\u003eIMPORTANT\u003c/b\u003e\u003c/td\u003e\n\u003ctd\u003eTo set the cache size in terms of object memory VM options have to be enabled while executing the main class of your project.\u003cbr\u003e\u003cb\u003eOtherwise, this can be skipped if object count option is used.\u003c/b\u003e\u003cbr\u003e\n Refer:\u003ca href=\"#323-cache-memory-types\"\u003eCache Memory Types\u003c/a\u003e\u003cbr\u003e\n\u003cul\u003e\n\u003cli\u003eDownload the  \u003ca href=\"https://mvnrepository.com/artifact/com.github.lekhana3003/SimplCache\"\u003eJAR\u003c/a\u003e\u003cbr\u003e\u003c/li\u003e\n\u003cli\u003eExecute java function by enabling VM options as: java -javaagent:\"path to downloaded jar\"\u003cbr\u003e\nEx:java -javaagent:\"../SimplCache.jar\"\u003c/li\u003e\n\u003c/ul\u003e\nFor Reference:\u003cbr\u003e\n\u003ca href=\"https://stackoverflow.com/questions/10639322/how-can-i-specify-the-default-jvm-arguments-for-programs-i-run-from-eclipse\"\u003eVM Options in Eclipse\u003c/a\u003e\u003cbr\u003e\n\u003ca href=\"https://stackoverflow.com/questions/45115208/how-to-set-javaagent-in-intellij-idea-vm-options\"\u003eVM Options in Intellij\u003c/a\u003e\u003cbr\u003e\n\u003ca href=\"https://web.archive.org/web/20141014195801/http://dhruba.name/2010/02/07/creation-dynamic-loading-and-instrumentation-with-javaagents/\"\u003eDynamically Enabling VM options\u003c/a\u003e\n \u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\n## 3. Usage\n\n### 3.1 Getting Started\nTo implement cache using the library, it requires some methods to be implemented which are present in the interfaces\n\u003cb\u003eCacheDB\u003c/b\u003e and \u003cb\u003ePersistentDB\u003c/b\u003e. The SimplCache object is built using the SimplCache Builder.\nThe Constructor of the builder takes two objects of CacheDB and PersistentDB.The model of the object that has to be stored in the cache has to be provided while implementing the interfaces.\u003cbr\u003e\nExample:\u003cbr\u003e\nThe object to be stored in the cache is Car Model.\u003cbr\u003e\nFor CacheDB:\n```java\npublic class CacheDBImpl implements CacheDB\u003cCar\u003e {\n...\n}\n```\nFor PersistentDB:\n```java\npublic class PersistentDBImpl implements PersistentDB\u003cCar\u003e {\n...\n}\n```\n\nTo build the SimplCache Object:\n\n```java\nCacheDBImpl cacheDB=new CacheDBImpl();\nPersistentDBImpl persistentDB= new PersistentDBImpl();\nSimplCache\u003cCar\u003e simplCache=new SimplCache.SimplCacheBuilder\u003cCar\u003e(cacheDB,persistentDB).build()\n```\n---\n**NOTE:**\n\nBy default, the Eviction policy is set to LRU and Cache type is set as Write-through.\n\n---\n### 3.2 Setting Cache Properties\n#### 3.2.1 Eviction Policy\n\u003cb\u003esetEvictionPolicy\u003c/b\u003e is used to set the eviction policy which accepts an enum of \u003cb\u003eEVICTION_TYPES\u003c/B\u003e.\nThere are two types of eviction policies provided currently,\n* LRU Eviction\u003cbr\u003e\nWhenever a new object is put into the cache the least recently used object is evicted from cache after writing the object into cache.\n    ```java\n    SimplCache\u003cCar\u003e simplCache=new SimplCache.SimplCacheBuilder\u003cCar\u003e(cacheDB,persistentDB)\n            .setEvictionPolicy(SimplCache.EVICTION_TYPES.LRU_EVICTION)\n            .build();\n    ```\n* Timed Eviction\u003cbr\u003e\nTime eviction is used when the cache objects have to remain in cache only for certain amount of time.\nBy setting this property, a new single thread runs parallel to the main thread which is responsible for removing the object from the cache after the time out.\nBefore evicting the object from the cache the current data is automatically written into the persistent database. \u003cbr\u003e\u003cbR\u003e\n\u003cb\u003esetTimeEvictionInterval()\u003c/b\u003e method is used to set the interval after which the object in cache expires.It accepts time integer and the unit of time as TimeUnit Object.If time eviction interval is not set, default value of 10 minutes is set. \u003cbr\u003e\n    ```java\n    SimplCache\u003cCar\u003e simplCache=new SimplCache.SimplCacheBuilder\u003cCar\u003e(cacheDB,persistentDB)\n            .setEvictionPolicy(SimplCache.EVICTION_TYPES.TIME_EVICTION)\n            .setTimeEvictionInterval(30,TimeUnit.SECONDS)\n            .build();\n    ```\n---\n**NOTE:**\n\nThe implemeneted  time eviction follows a combination of LRU and Time eviction i.e. if the cache is full at any point and no object in cache has timed out then the least recently object is removed from the cache to add the new object. \u003cbR\u003e\u003cbr\u003e\n\n---\n#### 3.2.2 Cache Type properties\n\u003cb\u003esetCacheType()\u003c/b\u003e method is used to set the cache type of the cache. It accepts an enum \u003cb\u003eCACHE_TYPES\u003c/b\u003e.There are two types of cache available currently,\n* Write-Through\u003cbr\u003e\nThe object is immediately written into persistent database after writing into cache database.\n    ```java\n    SimplCache\u003cCar\u003e simplCache=new SimplCache.SimplCacheBuilder\u003cCar\u003e(cacheDB,persistentDB)\n            .setCacheType(SimplCache.CACHE_TYPES.WRITE_THROUGH)\n            .build();\n    ```\n* Write-Back\u003cbr\u003e\nThe object in cache is not immediately updated in cache but later in time.\nThere are two types of write-back options available,\n    * NO_AUTO\u003cbR\u003e\n    The write back into the persistent database from cache database happens only when \u003cb\u003ewriteBack()\u003c/b\u003e method is called or when the object is evicted from cache. The write back does not happen automatically.\n        ```java\n          SimplCache\u003cCar\u003e simplCache=new SimplCache.SimplCacheBuilder\u003cCar\u003e(cacheDB,persistentDB)\n                            .setCacheType(SimplCache.CACHE_TYPES.WRITE_BACK)\n                            .build();\n         ```\n  * AUTO\u003cbr\u003e\n  In this variation write back occurs at regular interval which is given by the user. A seperate new single thread is created and this thread is responsible for writing back only those objects that have been modified.\n  \u003cb\u003esetWriteBackInterval()\u003c/b\u003e takes two parameters time integer and the unit of time as TimeUnit Object. \n      ```java\n    SimplCache\u003cCar\u003e simplCache=new SimplCache.SimplCacheBuilder\u003cCar\u003e(cacheDB,persistentDB)\n                        .setCacheType(SimplCache.CACHE_TYPES.WRITE_BACK)\n                        .setWriteBackInterval(30,TimeUnit.SECONDS)\n                        .build();\n      ```\n#### 3.2.3 Cache Memory Types\nThe library provides two types of cache size options, i.e. depending on Objects size and Objects count.\u003cbR\u003e\nTo set the memory properties, \u003cb\u003esetCacheMemoryProperties()\u003c/b\u003e is used. It takes two parameters,\n* MEMORY_TYPES enum which has OBJECTS_SIZE and OBJECTS_COUNT\n* Maximum size of the cache, the size of cache is in KiloBytes(KB) if memory type is given as OBJECTS_SIZE and count if the OBJECTS_COUNT is given as memory type.\u003cbr\u003e\n\nThe default value of MEMORY_TYPES is OBJECT_COUNT and the default size is 50.\n```java\nSimplCache\u003cCar\u003e simplCache=new SimplCache.SimplCacheBuilder\u003cCar\u003e(cacheDB,persistentDB)\n        .setCacheMemoryProperties(SimplCache.MEMORY_TYPES.OBJECTS_COUNT,10)\n        .build();\n```\n\n### 3.3 Put Method\n\nThis is an important method which is used to put object inside the cache. If the the cache is full, this method is responsible for performing the eviction according to the eviction policy selected by the user.\nThis method takes two parameters Key(String) and the Object.\n```java\nCar car=new Car(\"2\",\"Car Model\",\"2020\");\nsimplCache.put(\"2\",car);\n```\nAnother variation of this method,\nIf the user requires the object only to be added into cache but not into persistent database i.e if the user wants the put method not to perform write-through or write-back\nthe user can use this variation.\n```java\nCar car=new Car(\"key\",\"Car Model\",\"2020\");\nsimplCache.put(\"key\",car, SimplCache.POLICY_CONTROL.WITHOUT_POLICY);\n```\n### 3.4 Get Method\nThis method gets the object from the cache. If the object is not present in the cache, this method fetches the object from persistent database and also adds this object into the cache.\nThis method requires the key of the object.\n```java\nCar car = simplCache.get(\"key\");\n```\n### 3.5 Write-Back Method\nThis method is responsible for writing the cache objects into persistent database. This method writes only the object which have been modified.\nThis can be used whenever user wants to manually write the modified objects into the persistent database.\n\n```java\nsimplCache.writeBack();\n```\n### 3.6 Flush Method\nThis method is used to clear all the objects in cache. It accepts a single parameter of \u003cb\u003eWRITEBACKPARAMETER\u003c/b\u003e enum.\nThis parameter given by the user decides if the modified objects should be written into the persistent database before flushing.\n* WITH_WRITE_BACK\n    ```java\n    simplCache.flush(SimplCache.WRITEBACKPARAMETER.WITH_WRITE_BACK);\n    ```\n* WITHOUT_WRITE_BACK\n    ```java\n    simplCache.flush(SimplCache.WRITEBACKPARAMETER.WITHOUT_WRITE_BACK);\n    ```\n### 3.7 Close Method\nThis method is used to close all the resources that have been opened by the SimplCache object.\nThe database connections of CacheDB and PersistentDB can be closed using this function. The user has option to override if the user chooses to.\n\u003cbr\u003e The close method takes a single parameter.\nThis parameter given by the user decides if the modified objects should be written into the persistent database before closing.\n* WITH_WRITE_BACK\n    ```java\n    simplCache.close(SimplCache.WRITEBACKPARAMETER.WITH_WRITE_BACK);\n    ```\n* WITHOUT_WRITE_BACK\n    ```java\n    simplCache.close(SimplCache.WRITEBACKPARAMETER.WITHOUT_WRITE_BACK);\n    ```\n### 3.8 Save State\n\n##### Saving:\nThis method is used to save the state of cache at any given time. This method returns a string which is encrypted with default encryption algorithm.\nIf the user wants to implement any other encryption mechanism, the user is required to pass an object of class which has implemented \u003cb\u003eSimplCacheEncryptor\u003c/b\u003e. The cache objects are written back into persistent database before saving the state,\nThis method returns only the keys of cache object and also stores the properties which are set for the cache in the SimplCache object. It does not store the entire object which is stored in the cache. \nThe two variations as follows,\u003cbr\u003e\n* With default encryptor,\n    ```java\n    String state = simplCache.saveState();\n    ```\n* With implemenation of SimplCacheEncryptor\u003cbr\u003e\n    Implemenation class\n    ```java\n    public class SimplCacheEncryptorImpl implements SimplCacheEncryptor {\n        ...\n    }\n    ```\n    ```java\n    SimplCacheEncryptorImpl simplCacheEncryptorImpl=new SimplCacheEncryptorImpl();\n    String state = simplCache.saveState(simplCacheEncryptorImpl);\n    ```\n##### Building from save state:\n This method is used to build back the cache from the string which is returned by the \u003cb\u003esaveState()\u003c/b\u003e method.\n This method restores cache objects from persistent database.\n This method takes cacheDB and persistenseDB implemented objects again along with optional \u003cb\u003eSimplCacheEncryptor\u003c/b\u003e object.  \n* With default encryptor,\n    ```java\n    SimplCache\u003cCar\u003e simplCache1=SimplCache.buildFromSaveState(state,cacheDB,persistentDB);\n    ```\n* With implemenation of SimplCacheEncryptor\u003cbr\u003e\n    ```java\n    SimplCache\u003cCar\u003e simplCache1=SimplCache.buildFromSaveState(state,cacheDB,persistentDB,simplCacheEncryptorImpl);\n    ```\n---\n**NOTE:**\n\nThe default encryptor does not guarantee any security.\n\n---\n\n## 4. Example\n[Spring Boot implemenation of SimplCache Library](https://github.com/lekhana3003/SimplCacheSpringDemo)\n\n## 5. License\n\n```\n   Copyright 2020 Lekhana Ganji\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n```\n\n## 6. Author\n* Author: Lekhana Ganji\n* Email: \u003ca href=\"mailto:lekhanag.3003@gmail.com\"\u003elekhanag.3003@gmail.com \u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flekhana3003%2Fsimplcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flekhana3003%2Fsimplcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flekhana3003%2Fsimplcache/lists"}