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

bug: ipns doesn't purge cache based on TTL #479

Closed
SgtPooki opened this issue Mar 28, 2024 · 0 comments · Fixed by #482
Closed

bug: ipns doesn't purge cache based on TTL #479

SgtPooki opened this issue Mar 28, 2024 · 0 comments · Fixed by #482

Comments

@SgtPooki
Copy link
Member

SgtPooki commented Mar 28, 2024

need to resolve #473 (comment). Summary of comment below:

if we don't store something like cacheEOL or storedAt timestamp, then we have no way to, "[respect] the TTL value"

this is the current flow:

requesting record for the first time

  1. check if this.localStore has record // NO
  2. query network for the record.
  3. validate that record is correct
  4. store record in cache (has ttl)
  5. return record to user

later requests for record (with default nocache=undefined)

  1. check if this.localStore has record // yes
  2. return cached record

we essentially need a check between 1 & 2 of later requests for record that will check if the record is expired.. unless this.localStore is already handling expiry, but it doesn't seem like it is:

╰─ ✔ ❯ rg 'localStore' packages/ipns
packages/ipns/src/routing/local-store.ts
26:export function localStore (datastore: Datastore): LocalStore {

packages/ipns/src/index.ts
240:import { localStore, type LocalStore } from './routing/local-store.js'
406:  private readonly localStore: LocalStore
416:    this.localStore = localStore(components.datastore)
426:      if (await this.localStore.has(routingKey, options)) {
428:        const buf = await this.localStore.get(routingKey, options)
437:      await this.localStore.put(routingKey, marshaledRecord, options)
536:    const cached = await this.localStore.has(routingKey, options)
543:        const record = await this.localStore.get(routingKey, options)
604:    await this.localStore.put(routingKey, record, options)

packages/ipns/src/routing/pubsub.ts
10:import { localStore, type LocalStore } from './local-store.js'
34:  private readonly localStore: LocalStore
40:    this.localStore = localStore(components.datastore)
74:    if (await this.localStore.has(routingKey)) {
75:      const currentRecord = await this.localStore.get(routingKey)
91:    await this.localStore.put(routingKey, message.data)
131:      return await this.localStore.get(routingKey, options)

we have no calls to remove, and localStore doesn't have any methods other than put/get/has, and nothing called on the datastore (given in localStore creation) other than put/get/has

@SgtPooki SgtPooki changed the title ipns: purging based on TTL bug: ipns doesn't purge cache based on TTL Apr 2, 2024
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 a pull request may close this issue.

1 participant