Skip to content

Commit 264f1d3

Browse files
committed
feat: use get instead of getAsync (hiero-ledger#4558)
Signed-off-by: Mariusz Jasuwienas <jasuwienas@gmail.com>
1 parent 4750ac7 commit 264f1d3

File tree

25 files changed

+86
-152
lines changed

25 files changed

+86
-152
lines changed

packages/relay/src/lib/admin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class AdminImpl implements Admin {
5757
public async config(): Promise<IAdminConfig> {
5858
const cacheKey = `${constants.CACHE_KEY.ADMIN_CONFIG}`;
5959

60-
let info: IAdminConfig = await this.cacheService.getAsync(cacheKey, AdminImpl.config);
60+
let info: IAdminConfig = await this.cacheService.get(cacheKey, AdminImpl.config);
6161
if (!info) {
6262
const maskedEnvs = ConfigService.getAllMasked();
6363
info = {

packages/relay/src/lib/clients/cache/ICacheClient.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
export interface ICacheClient {
44
keys(pattern: string, callingMethod: string): Promise<string[]>;
5-
get(key: string, callingMethod: string): Promise<any>;
5+
get<T = any>(key: string, callingMethod: string): Promise<T>;
66
set(key: string, value: any, callingMethod: string, ttl?: number): Promise<void>;
77
multiSet(keyValuePairs: Record<string, any>, callingMethod: string, ttl?: number | undefined): Promise<void>;
88
pipelineSet(keyValuePairs: Record<string, any>, callingMethod: string, ttl?: number | undefined): Promise<void>;
@@ -11,9 +11,4 @@ export interface ICacheClient {
1111
incrBy(key: string, amount: number, callingMethod: string): Promise<number>;
1212
rPush(key: string, value: any, callingMethod: string): Promise<number>;
1313
lRange<T = any>(key: string, start: number, end: number, callingMethod: string): Promise<T[]>;
14-
15-
/**
16-
* @deprecated Alias of `get`; consider removing. Left in place to avoid modifying the CacheService interface.
17-
*/
18-
getAsync<T = any>(key: string, callingMethod: string): Promise<T>;
1914
}

packages/relay/src/lib/clients/cache/localLRUCache.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,6 @@ export class LocalLRUCache implements ICacheClient {
110110
return `${LocalLRUCache.CACHE_KEY_PREFIX}${key}`;
111111
}
112112

113-
/**
114-
* Alias for the `get` method.
115-
*
116-
* @param key - The key associated with the cached value.
117-
* @param callingMethod - The name of the method calling the cache.
118-
* @returns The cached value if found, otherwise null.
119-
*
120-
* @deprecated use `get` instead.
121-
*/
122-
public getAsync(key: string, callingMethod: string): Promise<any> {
123-
return this.get(key, callingMethod);
124-
}
125-
126113
/**
127114
* Retrieves a cached value associated with the given key.
128115
* If the value exists in the cache, updates metrics and logs the retrieval.

packages/relay/src/lib/clients/cache/measurableCache.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export class MeasurableCache implements ICacheClient {
1515

1616
public static readonly methods = {
1717
GET: 'get',
18-
GET_ASYNC: 'getAsync',
1918
SET: 'set',
2019
DELETE: 'delete',
2120
MSET: 'mSet',
@@ -40,19 +39,6 @@ export class MeasurableCache implements ICacheClient {
4039
this.callMap = callMap;
4140
}
4241

43-
/**
44-
* Alias for the `get` method.
45-
*
46-
* @param key - The key associated with the cached value.
47-
* @param callingMethod - The name of the method calling the cache.
48-
* @returns The cached value if found, otherwise null.
49-
*
50-
* @deprecated use `get` instead.
51-
*/
52-
public getAsync(key: string, callingMethod: string): Promise<any> {
53-
return this.decorated.get(key, callingMethod);
54-
}
55-
5642
/**
5743
* Calls the method that retrieves a cached value associated with the given key
5844
* and tracks how many times this event occurs.
@@ -62,7 +48,7 @@ export class MeasurableCache implements ICacheClient {
6248
* @returns The cached value if found, otherwise null.
6349
*/
6450
public async get(key: string, callingMethod: string): Promise<any> {
65-
this.count(callingMethod, MeasurableCache.methods.GET_ASYNC);
51+
this.count(callingMethod, MeasurableCache.methods.GET);
6652
return await this.decorated.get(key, callingMethod);
6753
}
6854

packages/relay/src/lib/clients/cache/redisCache/redisCache.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,6 @@ export class RedisCache implements ICacheClient {
6565
return `${RedisCache.CACHE_KEY_PREFIX}${key}`;
6666
}
6767

68-
/**
69-
* Alias for the `get` method.
70-
*
71-
* @param key - The key associated with the cached value.
72-
* @param callingMethod - The name of the method calling the cache.
73-
* @returns The cached value if found, otherwise null.
74-
*
75-
* @deprecated use `get` instead.
76-
*/
77-
public getAsync(key: string, callingMethod: string): Promise<any> {
78-
return this.get(key, callingMethod);
79-
}
80-
8168
/**
8269
* Retrieves a value from the cache.
8370
*

packages/relay/src/lib/clients/cache/redisCache/safeRedisCache.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@ import { RedisCache } from './redisCache';
1212
* Thanks to that our application will be able to continue functioning even with Redis being down...
1313
*/
1414
export class SafeRedisCache extends RedisCache {
15-
/**
16-
* Alias for the `get` method.
17-
*
18-
* @param key - The key associated with the cached value.
19-
* @param callingMethod - The name of the method calling the cache.
20-
* @returns The cached value if found, otherwise null.
21-
*
22-
* @deprecated use `get` instead.
23-
*/
24-
public getAsync(key: string, callingMethod: string): Promise<any> {
25-
return this.get(key, callingMethod);
26-
}
27-
2815
/**
2916
* Retrieves a value from the cache.
3017
*

packages/relay/src/lib/clients/mirrorNodeClient.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ export class MirrorNodeClient {
623623

624624
public async getBlock(hashOrBlockNumber: string | number, requestDetails: RequestDetails): Promise<MirrorNodeBlock> {
625625
const cachedLabel = `${constants.CACHE_KEY.GET_BLOCK}.${hashOrBlockNumber}`;
626-
const cachedResponse: any = await this.cacheService.getAsync(cachedLabel, MirrorNodeClient.GET_BLOCK_ENDPOINT);
626+
const cachedResponse: any = await this.cacheService.get(cachedLabel, MirrorNodeClient.GET_BLOCK_ENDPOINT);
627627
if (cachedResponse) {
628628
return cachedResponse;
629629
}
@@ -683,7 +683,7 @@ export class MirrorNodeClient {
683683

684684
public async getIsValidContractCache(contractIdOrAddress: string): Promise<any> {
685685
const cachedLabel = this.getIsValidContractCacheLabel(contractIdOrAddress);
686-
return await this.cacheService.getAsync(cachedLabel, MirrorNodeClient.GET_CONTRACT_ENDPOINT);
686+
return await this.cacheService.get(cachedLabel, MirrorNodeClient.GET_CONTRACT_ENDPOINT);
687687
}
688688

689689
public async isValidContract(contractIdOrAddress: string, requestDetails: RequestDetails, retries?: number) {
@@ -707,7 +707,7 @@ export class MirrorNodeClient {
707707

708708
public async getContractId(contractIdOrAddress: string, requestDetails: RequestDetails, retries?: number) {
709709
const cachedLabel = `${constants.CACHE_KEY.GET_CONTRACT}.id.${contractIdOrAddress}`;
710-
const cachedResponse: any = await this.cacheService.getAsync(cachedLabel, MirrorNodeClient.GET_CONTRACT_ENDPOINT);
710+
const cachedResponse: any = await this.cacheService.get(cachedLabel, MirrorNodeClient.GET_CONTRACT_ENDPOINT);
711711
if (cachedResponse != undefined) {
712712
return cachedResponse;
713713
}
@@ -730,7 +730,7 @@ export class MirrorNodeClient {
730730

731731
public async getContractResult(transactionIdOrHash: string, requestDetails: RequestDetails) {
732732
const cacheKey = `${constants.CACHE_KEY.GET_CONTRACT_RESULT}.${transactionIdOrHash}`;
733-
const cachedResponse = await this.cacheService.getAsync(cacheKey, MirrorNodeClient.GET_CONTRACT_RESULT_ENDPOINT);
733+
const cachedResponse = await this.cacheService.get(cacheKey, MirrorNodeClient.GET_CONTRACT_RESULT_ENDPOINT);
734734

735735
if (cachedResponse) {
736736
return cachedResponse;
@@ -1057,7 +1057,7 @@ export class MirrorNodeClient {
10571057

10581058
public async getEarliestBlock(requestDetails: RequestDetails) {
10591059
const cachedLabel = `${constants.CACHE_KEY.GET_BLOCK}.earliest`;
1060-
const cachedResponse: any = await this.cacheService.getAsync(cachedLabel, MirrorNodeClient.GET_BLOCKS_ENDPOINT);
1060+
const cachedResponse: any = await this.cacheService.get(cachedLabel, MirrorNodeClient.GET_BLOCKS_ENDPOINT);
10611061
if (cachedResponse != undefined) {
10621062
return cachedResponse;
10631063
}
@@ -1359,7 +1359,7 @@ export class MirrorNodeClient {
13591359
const cachedLabel = `${constants.CACHE_KEY.RESOLVE_ENTITY_TYPE}_${entityIdentifier}${
13601360
timestamp ? `_${timestamp}` : ''
13611361
}`;
1362-
const cachedResponse: { type: string; entity: any } | undefined = await this.cacheService.getAsync(
1362+
const cachedResponse: { type: string; entity: any } | undefined = await this.cacheService.get(
13631363
cachedLabel,
13641364
callerName,
13651365
);

packages/relay/src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class EvmAddressHbarSpendingPlanRepository {
3535
*/
3636
async existsByAddress(evmAddress: string): Promise<boolean> {
3737
const key = this.getKey(evmAddress);
38-
const addressPlan = await this.cache.getAsync<IEvmAddressHbarSpendingPlan>(key, 'existsByAddress');
38+
const addressPlan = await this.cache.get<IEvmAddressHbarSpendingPlan>(key, 'existsByAddress');
3939
return !!addressPlan;
4040
}
4141

@@ -50,7 +50,7 @@ export class EvmAddressHbarSpendingPlanRepository {
5050
const key = this.getKey('*');
5151
const keys = await this.cache.keys(key, callingMethod);
5252
for (const key of keys) {
53-
const addressPlan = await this.cache.getAsync<IEvmAddressHbarSpendingPlan>(key, callingMethod);
53+
const addressPlan = await this.cache.get<IEvmAddressHbarSpendingPlan>(key, callingMethod);
5454
if (addressPlan?.planId === planId) {
5555
evmAddressPlans.push(new EvmAddressHbarSpendingPlan(addressPlan));
5656
}
@@ -67,7 +67,7 @@ export class EvmAddressHbarSpendingPlanRepository {
6767
const key = this.getKey('*');
6868
const keys = await this.cache.keys(key, callingMethod);
6969
for (const key of keys) {
70-
const addressPlan = await this.cache.getAsync<IEvmAddressHbarSpendingPlan>(key, callingMethod);
70+
const addressPlan = await this.cache.get<IEvmAddressHbarSpendingPlan>(key, callingMethod);
7171
if (addressPlan?.planId === planId) {
7272
if (this.logger.isLevelEnabled('trace')) {
7373
this.logger.trace(`Removing EVM address ${addressPlan.evmAddress} from HbarSpendingPlan with ID ${planId}`);
@@ -85,7 +85,7 @@ export class EvmAddressHbarSpendingPlanRepository {
8585
*/
8686
async findByAddress(evmAddress: string): Promise<EvmAddressHbarSpendingPlan> {
8787
const key = this.getKey(evmAddress);
88-
const addressPlan = await this.cache.getAsync<IEvmAddressHbarSpendingPlan>(key, 'findByAddress');
88+
const addressPlan = await this.cache.get<IEvmAddressHbarSpendingPlan>(key, 'findByAddress');
8989
if (!addressPlan) {
9090
throw new EvmAddressHbarSpendingPlanNotFoundError(evmAddress);
9191
}
@@ -122,7 +122,7 @@ export class EvmAddressHbarSpendingPlanRepository {
122122
*/
123123
async delete(evmAddress: string): Promise<void> {
124124
const key = this.getKey(evmAddress);
125-
const evmAddressPlan = await this.cache.getAsync<IEvmAddressHbarSpendingPlan>(key, 'delete');
125+
const evmAddressPlan = await this.cache.get<IEvmAddressHbarSpendingPlan>(key, 'delete');
126126
await this.cache.delete(key, 'delete');
127127
const errorMessage = evmAddressPlan
128128
? `Removed EVM address ${evmAddress} from HbarSpendingPlan with ID ${evmAddressPlan.planId}`

packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class HbarSpendingPlanRepository {
3838
*/
3939
async findById(id: string): Promise<IHbarSpendingPlan> {
4040
const key = this.getKey(id);
41-
const plan = await this.cache.getAsync<IHbarSpendingPlan>(key, 'findById');
41+
const plan = await this.cache.get<IHbarSpendingPlan>(key, 'findById');
4242
if (!plan) {
4343
throw new HbarSpendingPlanNotFoundError(id);
4444
}
@@ -154,7 +154,7 @@ export class HbarSpendingPlanRepository {
154154
this.logger.debug(`Retrieving amountSpent for HbarSpendingPlan with ID ${id}...`);
155155
}
156156
const key = this.getAmountSpentKey(id);
157-
return this.cache.getAsync(key, 'getAmountSpent').then((amountSpent) => parseInt(amountSpent ?? '0'));
157+
return this.cache.get(key, 'getAmountSpent').then((amountSpent) => parseInt(amountSpent ?? '0'));
158158
}
159159

160160
/**
@@ -184,7 +184,7 @@ export class HbarSpendingPlanRepository {
184184
await this.checkExistsAndActive(id);
185185

186186
const key = this.getAmountSpentKey(id);
187-
if (!(await this.cache.getAsync(key, 'addToAmountSpent'))) {
187+
if (!(await this.cache.get(key, 'addToAmountSpent'))) {
188188
if (this.logger.isLevelEnabled('trace')) {
189189
this.logger.trace(`No spending yet for HbarSpendingPlan with ID ${id}, setting amountSpent to ${amount}...`);
190190
}
@@ -205,7 +205,7 @@ export class HbarSpendingPlanRepository {
205205
async findAllActiveBySubscriptionTier(tiers: SubscriptionTier[]): Promise<IDetailedHbarSpendingPlan[]> {
206206
const callerMethod = this.findAllActiveBySubscriptionTier.name;
207207
const keys = await this.cache.keys(this.getKey('*'), callerMethod);
208-
const plans = await Promise.all(keys.map((key) => this.cache.getAsync<IHbarSpendingPlan>(key, callerMethod)));
208+
const plans = await Promise.all(keys.map((key) => this.cache.get<IHbarSpendingPlan>(key, callerMethod)));
209209
return Promise.all(
210210
plans
211211
.filter((plan) => tiers.includes(plan.subscriptionTier) && plan.active)

packages/relay/src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class IPAddressHbarSpendingPlanRepository {
3535
*/
3636
async existsByAddress(ipAddress: string): Promise<boolean> {
3737
const key = this.getKey(ipAddress);
38-
const addressPlan = await this.cache.getAsync<IIPAddressHbarSpendingPlan>(key, 'existsByAddress');
38+
const addressPlan = await this.cache.get<IIPAddressHbarSpendingPlan>(key, 'existsByAddress');
3939
return !!addressPlan;
4040
}
4141

@@ -50,7 +50,7 @@ export class IPAddressHbarSpendingPlanRepository {
5050
const key = this.getKey('*');
5151
const keys = await this.cache.keys(key, callingMethod);
5252
for (const key of keys) {
53-
const addressPlan = await this.cache.getAsync<IIPAddressHbarSpendingPlan>(key, callingMethod);
53+
const addressPlan = await this.cache.get<IIPAddressHbarSpendingPlan>(key, callingMethod);
5454
if (addressPlan?.planId === planId) {
5555
ipAddressPlans.push(new IPAddressHbarSpendingPlan(addressPlan));
5656
}
@@ -67,7 +67,7 @@ export class IPAddressHbarSpendingPlanRepository {
6767
const key = this.getKey('*');
6868
const keys = await this.cache.keys(key, callingMethod);
6969
for (const key of keys) {
70-
const addressPlan = await this.cache.getAsync<IIPAddressHbarSpendingPlan>(key, callingMethod);
70+
const addressPlan = await this.cache.get<IIPAddressHbarSpendingPlan>(key, callingMethod);
7171
if (addressPlan?.planId === planId) {
7272
if (this.logger.isLevelEnabled('trace')) {
7373
this.logger.trace(`Removing IP address from HbarSpendingPlan with ID ${planId}`);
@@ -85,7 +85,7 @@ export class IPAddressHbarSpendingPlanRepository {
8585
*/
8686
async findByAddress(ipAddress: string): Promise<IPAddressHbarSpendingPlan> {
8787
const key = this.getKey(ipAddress);
88-
const addressPlan = await this.cache.getAsync<IIPAddressHbarSpendingPlan>(key, 'findByAddress');
88+
const addressPlan = await this.cache.get<IIPAddressHbarSpendingPlan>(key, 'findByAddress');
8989
if (!addressPlan) {
9090
throw new IPAddressHbarSpendingPlanNotFoundError(ipAddress);
9191
}
@@ -116,7 +116,7 @@ export class IPAddressHbarSpendingPlanRepository {
116116
*/
117117
async delete(ipAddress: string): Promise<void> {
118118
const key = this.getKey(ipAddress);
119-
const ipAddressSpendingPlan = await this.cache.getAsync<IIPAddressHbarSpendingPlan>(key, 'delete');
119+
const ipAddressSpendingPlan = await this.cache.get<IIPAddressHbarSpendingPlan>(key, 'delete');
120120
await this.cache.delete(key, 'delete');
121121
const errorMessage = ipAddressSpendingPlan
122122
? `Removed IP address from HbarSpendingPlan with ID ${ipAddressSpendingPlan.planId}`

0 commit comments

Comments
 (0)