@bejibun/cache 0.1.0 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,38 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ---
5
5
 
6
+ ## [v0.1.11](https://github.com/crenata/bejibun-cache/compare/v0.1.0...v0.1.11) - 2025-11-23
7
+
8
+ ### 🩹 Fixes
9
+
10
+ ### 📖 Changes
11
+ What's New :
12
+ - Adding `ttl` supports for increment & decrement
13
+
14
+ ### ❤️Contributors
15
+ - Havea Crenata ([@crenata](https://github.com/crenata))
16
+
17
+ **Full Changelog**: https://github.com/crenata/bejibun-cache/blob/master/CHANGELOG.md
18
+
19
+ ---
20
+
21
+ ## [v0.1.1](https://github.com/crenata/bejibun-cache/compare/v0.1.0...v0.1.1) - 2025-11-23
22
+
23
+ ### 🩹 Fixes
24
+
25
+ ### 📖 Changes
26
+ What's New :
27
+ - Adding cache `ttl` support
28
+ - `.increment()` Increment cache counter
29
+ - `.decrement()` Decrement cache counter
30
+
31
+ ### ❤️Contributors
32
+ - Ghulje ([@ghulje](https://github.com/ghulje))
33
+
34
+ **Full Changelog**: https://github.com/crenata/bejibun-cache/blob/master/CHANGELOG.md
35
+
36
+ ---
37
+
6
38
  ## [v0.1.0](https://github.com/crenata/bejibun-cache/compare/v0.1.0...v0.1.0) - 2025-11-09
7
39
 
8
40
  ### 🩹 Fixes
package/README.md CHANGED
@@ -62,11 +62,14 @@ How to use tha package.
62
62
  ```ts
63
63
  import Cache from "@bejibun/cache";
64
64
 
65
- await Cache.remember("key", () => {}); // any
65
+ await Cache.remember("key", () => {}, 60 /* seconds */); // any
66
66
  await Cache.has("key"); // boolean
67
67
  await Cache.get("key"); // any
68
- await Cache.add("key", "Hello world"); // boolean
69
- await Cache.put("key", "Lorem ipsum"); // boolean
68
+ await Cache.add("key", "Hello world", 60 /* seconds */); // boolean
69
+ await Cache.put("key", "Lorem ipsum", 60 /* seconds */); // boolean
70
+ await Cache.forget("key"); // void
71
+ await Cache.increment("key"); // number
72
+ await Cache.decrement("key"); // number
70
73
  ```
71
74
 
72
75
  ## Contributors
@@ -74,15 +77,11 @@ await Cache.put("key", "Lorem ipsum"); // boolean
74
77
 
75
78
  ## ☕ Support / Donate
76
79
 
77
- If you find this project helpful and want to support it, you can donate via PayPal :
78
-
79
- [![Donate with PayPal](https://img.shields.io/badge/Donate-PayPal-blue.svg?logo=paypal)](https://paypal.me/hafiizhghulam)
80
-
81
- Or if you are prefer using crypto :
80
+ If you find this project helpful and want to support it, you can donate via crypto :
82
81
 
83
82
  | EVM | Solana |
84
83
  | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
85
84
  | <img src="https://github.com/crenata/bejibun/blob/master/public/images/EVM.png?raw=true" width="150" /> | <img src="https://github.com/crenata/bejibun/blob/master/public/images/SOL.png?raw=true" width="150" /> |
86
85
  | 0xdABe8750061410D35cE52EB2a418c8cB004788B3 | GAnoyvy9p3QFyxikWDh9hA3fmSk2uiPLNWyQ579cckMn |
87
86
 
88
- Or you can buy this `$BJBN (Bejibun)` tokens [here](https://pump.fun/coin/CQhbNnCGKfDaKXt8uE61i5DrBYJV7NPsCDD9vQgypump), beware of bots.
87
+ Or you can buy this `$BJBN (Bejibun)` tokens [here](https://pump.fun/coin/CQhbNnCGKfDaKXt8uE61i5DrBYJV7NPsCDD9vQgypump), beware of bots.
@@ -4,10 +4,12 @@ export default class CacheBuilder {
4
4
  constructor();
5
5
  private get config();
6
6
  private key;
7
- remember(key: string, callback: Function): Promise<any>;
7
+ remember(key: string, callback: Function, ttl?: number): Promise<any>;
8
8
  has(key: string): Promise<boolean>;
9
9
  get(key: string): Promise<any>;
10
- add(key: string, value: any): Promise<boolean>;
11
- put(key: string, value: any): Promise<boolean>;
10
+ add(key: string, value: any, ttl?: number): Promise<boolean>;
11
+ put(key: string, value: any, ttl?: number): Promise<boolean>;
12
12
  forget(key: string): Promise<void>;
13
+ increment(key: string, ttl?: number): Promise<number>;
14
+ decrement(key: string, ttl?: number): Promise<number>;
13
15
  }
@@ -26,14 +26,14 @@ export default class CacheBuilder {
26
26
  key(key) {
27
27
  return `${this.prefix}/${key}`;
28
28
  }
29
- async remember(key, callback) {
29
+ async remember(key, callback, ttl) {
30
30
  let data;
31
31
  switch (this.config.connection) {
32
32
  case "redis":
33
33
  data = await Redis.get(this.key(key));
34
34
  if (isEmpty(data)) {
35
35
  data = callback();
36
- await Redis.set(this.key(key), data);
36
+ await Redis.set(this.key(key), data, ttl);
37
37
  }
38
38
  break;
39
39
  default:
@@ -66,7 +66,7 @@ export default class CacheBuilder {
66
66
  }
67
67
  return data;
68
68
  }
69
- async add(key, value) {
69
+ async add(key, value, ttl) {
70
70
  let status = true;
71
71
  let data;
72
72
  try {
@@ -81,7 +81,7 @@ export default class CacheBuilder {
81
81
  if (isEmpty(data)) {
82
82
  switch (this.config.connection) {
83
83
  case "redis":
84
- await Redis.set(this.key(key), value);
84
+ await Redis.set(this.key(key), value, ttl);
85
85
  break;
86
86
  default:
87
87
  break;
@@ -98,12 +98,12 @@ export default class CacheBuilder {
98
98
  }
99
99
  return status;
100
100
  }
101
- async put(key, value) {
101
+ async put(key, value, ttl) {
102
102
  let status = true;
103
103
  try {
104
104
  switch (this.config.connection) {
105
105
  case "redis":
106
- await Redis.set(this.key(key), value);
106
+ await Redis.set(this.key(key), value, ttl);
107
107
  break;
108
108
  default:
109
109
  break;
@@ -124,4 +124,44 @@ export default class CacheBuilder {
124
124
  break;
125
125
  }
126
126
  }
127
+ async increment(key, ttl) {
128
+ let data;
129
+ switch (this.config.connection) {
130
+ case "redis":
131
+ data = Number(await Redis.get(this.key(key)));
132
+ if (isEmpty(data)) {
133
+ data = 1;
134
+ await Redis.set(this.key(key), data, ttl);
135
+ }
136
+ else {
137
+ data++;
138
+ await Redis.set(this.key(key), data, ttl);
139
+ }
140
+ break;
141
+ default:
142
+ data = 0;
143
+ break;
144
+ }
145
+ return data;
146
+ }
147
+ async decrement(key, ttl) {
148
+ let data;
149
+ switch (this.config.connection) {
150
+ case "redis":
151
+ data = Number(await Redis.get(this.key(key)));
152
+ if (isEmpty(data)) {
153
+ data = -1;
154
+ await Redis.set(this.key(key), data, ttl);
155
+ }
156
+ else {
157
+ data--;
158
+ await Redis.set(this.key(key), data, ttl);
159
+ }
160
+ break;
161
+ default:
162
+ data = 0;
163
+ break;
164
+ }
165
+ return data;
166
+ }
127
167
  }
@@ -1,8 +1,10 @@
1
1
  export default class Cache {
2
- static remember(key: string, callback: Function): Promise<any>;
2
+ static remember(key: string, callback: Function, ttl?: number): Promise<any>;
3
3
  static has(key: string): Promise<boolean>;
4
4
  static get(key: string): Promise<any>;
5
- static add(key: string, value: string): Promise<boolean>;
6
- static put(key: string, value: string): Promise<boolean>;
5
+ static add(key: string, value: any, ttl?: number): Promise<boolean>;
6
+ static put(key: string, value: any, ttl?: number): Promise<boolean>;
7
7
  static forget(key: string): Promise<void>;
8
+ static increment(key: string, ttl?: number): Promise<number>;
9
+ static decrement(key: string, ttl?: number): Promise<number>;
8
10
  }
package/facades/Cache.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import CacheBuilder from "../builders/CacheBuilder";
2
2
  export default class Cache {
3
- static async remember(key, callback) {
4
- return new CacheBuilder().remember(key, callback);
3
+ static async remember(key, callback, ttl) {
4
+ return new CacheBuilder().remember(key, callback, ttl);
5
5
  }
6
6
  static async has(key) {
7
7
  return new CacheBuilder().has(key);
@@ -9,13 +9,19 @@ export default class Cache {
9
9
  static async get(key) {
10
10
  return new CacheBuilder().get(key);
11
11
  }
12
- static async add(key, value) {
13
- return new CacheBuilder().add(key, value);
12
+ static async add(key, value, ttl) {
13
+ return new CacheBuilder().add(key, value, ttl);
14
14
  }
15
- static async put(key, value) {
16
- return new CacheBuilder().put(key, value);
15
+ static async put(key, value, ttl) {
16
+ return new CacheBuilder().put(key, value, ttl);
17
17
  }
18
18
  static async forget(key) {
19
19
  return new CacheBuilder().forget(key);
20
20
  }
21
+ static async increment(key, ttl) {
22
+ return new CacheBuilder().increment(key, ttl);
23
+ }
24
+ static async decrement(key, ttl) {
25
+ return new CacheBuilder().decrement(key, ttl);
26
+ }
21
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/cache",
3
- "version": "0.1.0",
3
+ "version": "0.1.11",
4
4
  "author": "Havea Crenata <havea.crenata@gmail.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@bejibun/app": "^0.1.22",
39
39
  "@bejibun/logger": "^0.1.22",
40
- "@bejibun/redis": "^0.1.33",
41
- "@bejibun/utils": "^0.1.20"
40
+ "@bejibun/redis": "^0.1.34",
41
+ "@bejibun/utils": "^0.1.21"
42
42
  }
43
43
  }