Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement api-cache-data-access module for api caching #523

Merged
merged 1 commit into from Dec 15, 2022

Conversation

beeman
Copy link
Contributor

@beeman beeman commented Dec 14, 2022

This PR implements a Redis based cache that allows us to easily store items in the cache.

The method we'll likely use most is the wrap method, that takes a namesapce, a unique key in that namespace, a value that returns the value to cache, either directly or by returning a promise, and lastly an optional ttl:

export type Value<T> = T | ValueFn<T>
export type ValueFn<T> = () => Promise<T>
async wrap<T>(namespace: CacheNamespace, key: string, value: Value<T>, ttl?: number): Promise<T> {}

Here some examples:

@Injectable()
class SomeService {

  constructor(private readonly data: ApiCoreDataAccessService) {}

  getNumber(): Promise<number> {
    return this.data.cache.wrap<number>('solana', 'some-number', 42)
  }

  getEndpoint(): Promise<string> {
    return this.data.cache.wrap<{  endpoint: string }>('solana', 'test', { endpoint: 'https://bla' })
  }

  getLatestBlockhash(appKey: string): Promise<LatestBlockhashResponse> {
    return this.data.cache.wrap<LatestBlockhashResponse>(
      'solana',
      `${appKey}:getLatestBlockhash`,
      () => this.getConnection(appKey).then((solana) => solana.getLatestBlockhash()),
      this.data.config.cache.solana.getLatestBlockhash.ttl,
    )
  }
}

Note, we need to pin the dependencies to these versions until this is fixed: dabroek/node-cache-manager-redis-store#53.

    "cache-manager": "^4.1.0",
    "cache-manager-redis-store": "2.0.0",

@nx-cloud
Copy link

nx-cloud bot commented Dec 14, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 488b5a4. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 6 targets

Sent with 💌 from NxCloud.

@beeman beeman force-pushed the beeman/solana-cache-get-latest-blockhash branch 2 times, most recently from 3b2662b to fe5538f Compare December 14, 2022 05:13
Base automatically changed from beeman/app-key to dev December 14, 2022 18:46
@beeman beeman force-pushed the beeman/solana-cache-get-latest-blockhash branch 3 times, most recently from 399f2f2 to 75ebd85 Compare December 14, 2022 19:06
@beeman beeman marked this pull request as ready for review December 14, 2022 19:10
@beeman beeman force-pushed the beeman/solana-cache-get-latest-blockhash branch from 9b9344f to 2478ca3 Compare December 15, 2022 01:17
@beeman beeman force-pushed the beeman/solana-cache-get-latest-blockhash branch from 2478ca3 to 488b5a4 Compare December 15, 2022 01:19
@beeman beeman merged commit 488b5a4 into dev Dec 15, 2022
@beeman beeman deleted the beeman/solana-cache-get-latest-blockhash branch December 15, 2022 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incompatible with NestJS cache store
1 participant