Skip to content

feat: add EID cache with per-source TTL#274

Open
MO-Thibault wants to merge 2 commits intoOptable:masterfrom
MO-Thibault:mo/eid-cache
Open

feat: add EID cache with per-source TTL#274
MO-Thibault wants to merge 2 commits intoOptable:masterfrom
MO-Thibault:mo/eid-cache

Conversation

@MO-Thibault
Copy link
Copy Markdown
Contributor

Summary

  • Adds eidCache config option to the SDK constructor — when enabled, targeting() merges fresh EIDs with previously cached EIDs from localStorage, applying per-source TTL expiry
  • Exports mergeWithCache() for wrappers using resolveMultiNodeTargeting (longitudeads, unwind, mediavine, weatherchannel)
  • Dispatches optableResolved event on window and document for backward compat with existing Prebid RTD listeners

Why

8 SDK wrapper bundles in optable-solutions copy-paste ~143 lines of identical EID caching logic (dedupeAndManageCache, saveResults, dispatchOptableResolved). 4 more customer repos (longitudeads, unwind, mediavine, weatherchannel) have similar implementations with minor variations. This centralizes the core logic so wrappers just set eidCache: { enabled: true }.

Usage

new OptableSDK({
  host: "customer.cloud.optable.co",
  site: "my-site",
  eidCache: {
    enabled: true,
    ttl: {                                          // optional overrides
      'custom-source.com': 5 * 24 * 60 * 60 * 1000
    }
  }
});

For wrappers using resolveMultiNodeTargeting:

import { mergeWithCache } from '@optable/web-sdk';

const result = await resolveMultiNodeTargeting(rules);
const merged = mergeWithCache(result, { enabled: true });

Default TTLs (baked in, overridable)

Source TTL
uidapi.com 1 day
id5-sync.com 7 days
default 3 days

Test plan

  • 12 unit tests covering merge logic, TTL expiry, collision handling, malformed storage, custom keys
  • 94% code coverage on eid-cache.ts
  • TypeScript compilation clean
  • Integration test with one wrapper bundle (arena — next PR)
  • Staging deployment to verify enrichment rates hold

🤖 Generated with Claude Code

Move extended EID caching logic from SDK wrapper bundles into the
web-sdk. Wrappers currently copy-paste ~143 lines of merge/TTL code
per customer — this centralizes it behind an `eidCache` config option.

When `eidCache.enabled`, targeting() merges fresh EIDs with previously
cached EIDs from localStorage, applying per-source TTL expiry
(uidapi.com=1d, id5-sync.com=7d, default=3d). Configurable via
the ttl map.

Also exports mergeWithCache() for wrappers using
resolveMultiNodeTargeting, and dispatches the optableResolved event
for backward compatibility with existing Prebid RTD listeners.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@jplaroche jplaroche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

2 participants