Skip to content

Commit

Permalink
Rename hotcache get and set methods. Those are reserved keywords and …
Browse files Browse the repository at this point in the history
…it is not a good idea to use them.
  • Loading branch information
slavcho committed Jul 2, 2023
1 parent 454bd66 commit 8ec5f6e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions apps/api/src/common/hotcache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class HotCache {
constructor(private ttl: number, private enabled: boolean) {}
private cache: { [key: string]: CacheObject } = {}

get(key: string) {
lookup(key: string) {
if (!this.enabled) {
return null
}
Expand All @@ -22,7 +22,7 @@ export class HotCache {
}

// make the ttl optional
set(key: string, value: any, ttl?: number) {
store(key: string, value: any, ttl?: number) {

Check warning on line 25 in apps/api/src/common/hotcache.ts

View workflow job for this annotation

GitHub Actions / Run API tests

Unexpected any. Specify a different type
if (!this.enabled) {
return
}
Expand Down
12 changes: 6 additions & 6 deletions apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export class DonationsService {
pageSize?: number,
): Promise<ListDonationsDto<DonationBaseDto>> {
const cacheKey = `donations-${campaignId}-${status}-${pageIndex}-${pageSize}`
const cachedDonations = this.cache.get(cacheKey)
const cachedDonations = this.cache.lookup(cacheKey)
if (cachedDonations) {
return cachedDonations
}
Expand Down Expand Up @@ -323,7 +323,7 @@ export class DonationsService {
total: count,
}

this.cache.set(cacheKey, result)
this.cache.store(cacheKey, result)

return result
}
Expand Down Expand Up @@ -681,7 +681,7 @@ export class DonationsService {
}

async getTotalDonatedMoney() {
const cachedAmount = this.cache.get('totalDonatedMoney')
const cachedAmount = this.cache.lookup('totalDonatedMoney')
if (cachedAmount) {
return { total: cachedAmount }
}
Expand All @@ -694,13 +694,13 @@ export class DonationsService {
})

// cache the amount for 30 seconds
this.cache.set('totalDonatedMoney', totalMoney._sum.amount)
this.cache.store('totalDonatedMoney', totalMoney._sum.amount)

return { total: totalMoney._sum.amount }
}

async getDonorsCount() {
const cachedCount = this.cache.get('donorsCount')
const cachedCount = this.cache.lookup('donorsCount')
if (cachedCount) {
return { count: cachedCount }
}
Expand All @@ -720,7 +720,7 @@ export class DonationsService {
const totalCount = donorsCount.length - 1 + anonymousDonations

// cache the count for 30 seconds
this.cache.set('donorsCount', totalCount)
this.cache.store('donorsCount', totalCount)

// substract one because we don't want to include anonymousDonation again
return { count: totalCount }
Expand Down

0 comments on commit 8ec5f6e

Please sign in to comment.