From 0198d9c9730109eda400a0fa59608c14c1cc80a4 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Fri, 2 Jan 2026 13:28:56 +0800 Subject: [PATCH] feat: ing... --- .gitignore | 9 ++- build.gradle | 69 +++++++++++++++++++ build.json | 17 +++++ justfile | 22 ++++++ .../hatter/tools/commons/cache/TestMain.java | 15 ++++ .../commons/cache/annotation/CacheObject.java | 17 +++++ .../commons/cache/resolver/CacheResolver.java | 6 ++ 7 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 build.gradle create mode 100644 build.json create mode 100644 justfile create mode 100644 src/main/java/me/hatter/tools/commons/cache/TestMain.java create mode 100644 src/main/java/me/hatter/tools/commons/cache/annotation/CacheObject.java create mode 100644 src/main/java/me/hatter/tools/commons/cache/resolver/CacheResolver.java diff --git a/.gitignore b/.gitignore index 5760a7a..138bb88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ +commons-cache.ipr +commons-cache.iml +commons-cache.iws +build/ +.gradle/ + # ---> Java # Compiled class file *.class @@ -31,7 +37,8 @@ replay_pid* .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..408a84d --- /dev/null +++ b/build.gradle @@ -0,0 +1,69 @@ +import groovy.json.JsonSlurper + +apply plugin: 'java' +apply plugin: 'idea' + +def baseProjectName = 'commons-cache-1.0' + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +def addRepo = new File(System.getProperty("user.home"), ".build_add.repo") + +repositories { + //mavenCentral() + flatDir { dirs "${System.env.JAVA_HOME}/jre/lib" } + flatDir { dirs "${System.env.JAVA_HOME}/lib" } + maven { + url 'https://maven.aliyun.com/repository/central' + } + if (addRepo.exists()) { maven() { url addRepo.text.trim() } } +} + +tasks.withType(JavaCompile) { + options.encoding = "UTF-8" +} + +// '-x test' skip unit test +defaultTasks 'packjar' + +task packjarsrc { + doLast { + ant.jar(destfile: "${baseProjectName}-sources.jar") { + fileset(dir: 'src/main/java', includes: '**/*.java') + } + } +} +packjarsrc.dependsOn build + +task packjar { + doLast { + def packtempclasses = "packtempclasses" + def libs = ant.path { + fileset(dir: 'build/libs', includes: '*.jar') + } + libs.list().each { + ant.unzip(dest: packtempclasses, src: it) + } + new File(packtempclasses + "/commons-jar-version-build.txt").write(new Date().format("yyyyMMdd"), "UTF-8") + ant.jar(destfile: "${baseProjectName}.jar") { + fileset(dir: packtempclasses, includes: '**/*.*') + } + ant.delete(dir: packtempclasses) + } +} +packjar.dependsOn packjarsrc + +dependencies { + implementation files(fileTree(dir: 'lib', includes: ['*.jar'], excludes: ['*-sources.jar', '*-javadoc.jar'])) + + def buildJSON = new JsonSlurper().parseText(new File("build.json").text) + if (buildJSON.repo != null && buildJSON.repo.dependencies != null) { + buildJSON.repo.dependencies.each { + implementation("${it}") + } + } + + testImplementation 'junit:junit:4.13.1' +} + diff --git a/build.json b/build.json new file mode 100644 index 0000000..387d885 --- /dev/null +++ b/build.json @@ -0,0 +1,17 @@ +{ + "java": "1.8", + "builder": { + "name": "gradle", + "version": "7.0" + }, + "repo": { + "gid": "me.hatter", + "aid": "commons-cache", + "jar": "commons-cache-1.0.jar", + "src": "commons-cache-1.0-sources.jar", + "dependencies": [ + "me.hatter:commons:4.29", + "redis.clients:jedis:7.1.0" + ] + } +} diff --git a/justfile b/justfile new file mode 100644 index 0000000..075c7dd --- /dev/null +++ b/justfile @@ -0,0 +1,22 @@ +_: + @just --list + +alias b:=build +alias pub:=publish +alias i:=ide + +# init for IDEA +ide: + buildj idea + +# build commons +build: + buildj clean + buildj + +# build and publish commons +publish: build + hatter repo publish + + + diff --git a/src/main/java/me/hatter/tools/commons/cache/TestMain.java b/src/main/java/me/hatter/tools/commons/cache/TestMain.java new file mode 100644 index 0000000..c0c8a96 --- /dev/null +++ b/src/main/java/me/hatter/tools/commons/cache/TestMain.java @@ -0,0 +1,15 @@ +package me.hatter.tools.commons.cache; + +import redis.clients.jedis.Jedis; + +public class TestMain { + + public static void main(String[] args) { + final Jedis jedis = new Jedis("127.0.0.1", 6379); + +// jedis.connect(); + jedis.set("a", "test"); + String v = jedis.get("a"); + System.out.println(v); + } +} diff --git a/src/main/java/me/hatter/tools/commons/cache/annotation/CacheObject.java b/src/main/java/me/hatter/tools/commons/cache/annotation/CacheObject.java new file mode 100644 index 0000000..e94a15b --- /dev/null +++ b/src/main/java/me/hatter/tools/commons/cache/annotation/CacheObject.java @@ -0,0 +1,17 @@ +package me.hatter.tools.commons.cache.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.concurrent.TimeUnit; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface CacheObject { + long ttl() default 60; + + long longTermTtl() default 60 * 24; + + TimeUnit unit() default TimeUnit.MINUTES; +} diff --git a/src/main/java/me/hatter/tools/commons/cache/resolver/CacheResolver.java b/src/main/java/me/hatter/tools/commons/cache/resolver/CacheResolver.java new file mode 100644 index 0000000..258de58 --- /dev/null +++ b/src/main/java/me/hatter/tools/commons/cache/resolver/CacheResolver.java @@ -0,0 +1,6 @@ +package me.hatter.tools.commons.cache.resolver; + +public interface CacheResolver { + + T resolve(); +}