From 51755281d3746acbd019016585e3f0c99aa5054f Mon Sep 17 00:00:00 2001
From: zhibing.pu <393733352@qq.com>
Date: 星期六, 17 八月 2024 15:35:58 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/wx/tools/WxCache.java |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 117 insertions(+), 0 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/wx/tools/WxCache.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/wx/tools/WxCache.java
new file mode 100644
index 0000000..a8b3560
--- /dev/null
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/wx/tools/WxCache.java
@@ -0,0 +1,117 @@
+package com.ruoyi.account.wx.tools;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 缓存
+ *
+ * @author xiaochen
+ */
+class WxCache {
+    /**
+     * 缓存的初始化容量
+     */
+    private int initialCapacity = 50;
+    /**
+     * 缓存最大容量
+     */
+    private long maximumSize = 200L;
+    /**
+     * 缓存时长
+     */
+    private long duration = 7000L;
+    /**
+     * 时长单位,自动转换
+     * 支持:
+     * 时
+     * 分
+     * 秒
+     * 天
+     */
+    private TimeUnit timeunit = TimeUnit.SECONDS;
+
+    public int getInitialCapacity() {
+        return initialCapacity;
+    }
+
+    public void setInitialCapacity(int initialCapacity) {
+        this.initialCapacity = initialCapacity;
+    }
+
+    public long getMaximumSize() {
+        return maximumSize;
+    }
+
+    public void setMaximumSize(long maximumSize) {
+        this.maximumSize = maximumSize;
+    }
+
+
+    public long getDuration() {
+        return duration;
+    }
+
+    public void setDuration(long duration) {
+        this.duration = duration;
+    }
+
+    public TimeUnit getTimeunit() {
+        return timeunit;
+    }
+
+    public void setTimeunit(TimeUnit timeunit) {
+        this.timeunit = timeunit;
+    }
+
+    public static class Builder {
+        private int initialCapacity;
+        private long maximumSize;
+        private long duration;
+        private TimeUnit timeunit;
+
+        public Builder setInitialCapacity(int initialCapacity) {
+            this.initialCapacity = initialCapacity;
+            return this;
+        }
+
+        public Builder setMaximumSize(long maximumSize) {
+            this.maximumSize = maximumSize;
+            return this;
+        }
+
+        public Builder setDuration(long duration) {
+            this.duration = duration;
+            return this;
+        }
+
+        public Builder setTimeUnit(TimeUnit timeunit) {
+            this.timeunit = timeunit;
+            return this;
+        }
+
+        public WxCache build() {
+            return new WxCache(this);
+        }
+    }
+
+    public static Builder options() {
+        return new Builder();
+    }
+
+    private WxCache(Builder builder) {
+        this.initialCapacity = 0 == builder.initialCapacity ? this.initialCapacity : builder.initialCapacity;
+        this.maximumSize = 0L == builder.maximumSize ? this.maximumSize : builder.maximumSize;
+        this.duration = 0L == builder.duration ? this.duration : builder.duration;
+        this.timeunit = null == builder.timeunit ? this.timeunit : builder.timeunit;
+    }
+
+    @Override
+    public String toString() {
+        return "WxCache{" +
+                "initialCapacity=" + initialCapacity +
+                ", maximumSize=" + maximumSize +
+                ", duration=" + duration +
+                ", timeunit=" + timeunit +
+                '}';
+    }
+}

--
Gitblit v1.7.1