xuhy
2025-04-08 d0aeeb1ad1d4e0419fd070a2d3045341bf30264f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.ruoyi.system.utils.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 +
                '}';
    }
}