vona-module-a-caching 5.0.4 → 5.0.6
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.
|
@@ -4,17 +4,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { isNil } from '@cabloy/utils';
|
|
8
7
|
import { BeanAopMethodBase, beanFullNameFromOnionName } from 'vona';
|
|
9
8
|
import { AopMethod } from 'vona-module-a-aspect';
|
|
10
|
-
import { combineCachingKey } from "../lib/utils.js";
|
|
9
|
+
import { combineCachingKey, isCachingKeyValid } from "../lib/utils.js";
|
|
11
10
|
let AopMethodCachingDel = class AopMethodCachingDel extends BeanAopMethodBase {
|
|
12
11
|
async execute(options, args, next, receiver, prop) {
|
|
13
12
|
// next
|
|
14
13
|
const value = await next();
|
|
15
14
|
// key
|
|
16
15
|
const key = combineCachingKey(options, args, receiver, prop);
|
|
17
|
-
if (
|
|
16
|
+
if (!isCachingKeyValid(key))
|
|
18
17
|
return value;
|
|
19
18
|
// cache
|
|
20
19
|
const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
|
|
@@ -4,15 +4,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { isNil } from '@cabloy/utils';
|
|
8
7
|
import { BeanAopMethodBase, beanFullNameFromOnionName } from 'vona';
|
|
9
8
|
import { AopMethod } from 'vona-module-a-aspect';
|
|
10
|
-
import { combineCachingKey } from "../lib/utils.js";
|
|
9
|
+
import { combineCachingKey, isCachingKeyValid } from "../lib/utils.js";
|
|
11
10
|
let AopMethodCachingGet = class AopMethodCachingGet extends BeanAopMethodBase {
|
|
12
11
|
async execute(options, args, next, receiver, prop) {
|
|
13
12
|
// key
|
|
14
13
|
const key = combineCachingKey(options, args, receiver, prop);
|
|
15
|
-
if (
|
|
14
|
+
if (!isCachingKeyValid(key))
|
|
16
15
|
return next();
|
|
17
16
|
// cache
|
|
18
17
|
const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
|
|
@@ -4,17 +4,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { isNil } from '@cabloy/utils';
|
|
8
7
|
import { BeanAopMethodBase, beanFullNameFromOnionName } from 'vona';
|
|
9
8
|
import { AopMethod } from 'vona-module-a-aspect';
|
|
10
|
-
import { combineCachingKey, combineCachingValue } from "../lib/utils.js";
|
|
9
|
+
import { combineCachingKey, combineCachingValue, isCachingKeyValid } from "../lib/utils.js";
|
|
11
10
|
let AopMethodCachingSet = class AopMethodCachingSet extends BeanAopMethodBase {
|
|
12
11
|
async execute(options, args, next, receiver, prop) {
|
|
13
12
|
// next
|
|
14
13
|
const value = await next();
|
|
15
14
|
// key
|
|
16
15
|
const key = combineCachingKey(options, args, receiver, prop);
|
|
17
|
-
if (
|
|
16
|
+
if (!isCachingKeyValid(key))
|
|
18
17
|
return value;
|
|
19
18
|
// value
|
|
20
19
|
const cacheValue = combineCachingValue(options, args, receiver, prop, value);
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ import type { IAopMethodOptionsCachingSet } from '../bean/aopMethod.cachingSet.t
|
|
|
3
3
|
import type { TypeCachingActionOptions } from '../types/caching.ts';
|
|
4
4
|
export declare function combineCachingKey(options: TypeCachingActionOptions, args: [], receiver: BeanBase, prop: string): any;
|
|
5
5
|
export declare function combineCachingValue(options: IAopMethodOptionsCachingSet, args: [], receiver: BeanBase, prop: string, value: any): any;
|
|
6
|
+
export declare function isCachingKeyValid(key: any): boolean;
|
package/dist/lib/utils.js
CHANGED
|
@@ -19,6 +19,8 @@ export function combineCachingKey(options, args, receiver, prop) {
|
|
|
19
19
|
prop,
|
|
20
20
|
options,
|
|
21
21
|
self: receiver,
|
|
22
|
+
app: cast(receiver).app,
|
|
23
|
+
ctx: cast(receiver).ctx,
|
|
22
24
|
});
|
|
23
25
|
}
|
|
24
26
|
// default
|
|
@@ -43,8 +45,13 @@ export function combineCachingValue(options, args, receiver, prop, value) {
|
|
|
43
45
|
prop,
|
|
44
46
|
options,
|
|
45
47
|
self: receiver,
|
|
48
|
+
app: cast(receiver).app,
|
|
49
|
+
ctx: cast(receiver).ctx,
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
52
|
// default
|
|
49
53
|
return value;
|
|
50
54
|
}
|
|
55
|
+
export function isCachingKeyValid(key) {
|
|
56
|
+
return !isNil(key) && key !== false && key !== '';
|
|
57
|
+
}
|