You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
memcached: configurable expiry per URI class, miss marker, ClearCache without flush_all - #104
Makes the memcached cache's expiry configurable per URI class. Also stops ClearCache() from wiping the shared cache, and adds a short-lived negative cache for lookups AYON can't resolve.
Three stacked PRs against enhancement/featuriing-memcached:
this one: configurable expiry, miss marker, ClearCache without flush_all
up/memcached-mget batch prewarm reads with memcached_mget (stacked on this)
up/unmapped-root-miss-marker a cached path with an unmapped root is a miss (stacked on up/memcached-mget)
Each later PR contains the earlier ones' commits. Merge in order; after each merge the next PR's diff shrinks to its own commits.
We have run this stack in production since 2026-10-27, on Houdini 21.0.559/700/792, Houdini 22.0.368, Maya 2026.2 and standalone OpenUSD 25.05, with one memcached per region in four regions.
Why
Every write had a hard-coded 1 h TTL (memcachedHandler.h, expireSeconds = 3600). In production, 80–95 % of what we wrote expired, more than half of it never read, and every session after a break started cold. Integer versions never change, so they don't need to expire at all.
ClearCache() ran flush_all. One artist pressing Houdini's "clear resolver cache" emptied the cache for the whole site: 7–23 flushes per site in 37 days.
Changelog
Setting
Applies to
Default
Values
AYON_MEMCACHED_EXPIRE_SECONDS
integer versions (immutable)
0 (never)
0, >0 s
AYON_MEMCACHED_HERO_EXPIRE_SECONDS
version=hero
3600
-1 bypass, 0, >0 s
AYON_MEMCACHED_LATEST_EXPIRE_SECONDS
version=latest / latestdone
-1 (never touches memcached)
-1, 0, >0 s
AYON_MEMCACHED_MISS_EXPIRE_SECONDS
lookups AYON has no path for
60
-1 off, >0 s (0 refused)
Classification uses the URI's version query value, normalised like the server does (trimmed, lowercased, one leading v dropped). Only an integer is immutable. A missing version, * or any other value gets the latest class: the server then matches any version, so there is no stable answer to cache. Precedence is Latest > Hero > Immutable.
Out-of-range values: expiry is capped at memcached's 30-day relative limit, because larger values are read as absolute timestamps and expire instantly. Invalid values fall back to the default with a TF_WARN.
Miss marker: stored as an empty value, which builds without miss markers read as a plain miss. It is never returned as a path. On read it is a known miss: no AYON call and no in-process insert. The process that writes it keeps no in-process entry either, so a publish is seen once the marker expires or is deleted. Its TTL never exceeds the URI's class TTL. Transport and parse failures are not misses and get no marker. (Older builds log memcached get failed: SUCCESS when they read a marker; harmless, and only while old and new builds share a cache.)
ClearCache() clears the in-process caches. It deletes only this process's hero and latest keys from memcached (skipping a class set to -1, which never wrote them) and leaves integer keys alone. flushAll is removed.
Miss-marker deletes (ClearCache() for the misses this process saw, DeleteFromCache(uri) for one URI) remove a key only while it still holds the marker, so a path stored in the meantime is kept.
Delete failures now warn like get and set failures do.
Lock order: kept the scoping from 5c2c1fe ("fix possible deadlock"). s_memcachedMutex is never held together with the cache locks, including in the new key-delete loop in ClearCache.
Followed by up/memcached-mget and up/unmapped-root-miss-marker
Type of Change
New feature (non-breaking change which adds functionality)
Bug fix (non-breaking change which fixes an issue)
Additional info
Testing
tests/memcachedExpiryTest.cpp (standalone): g++ -std=c++17 -I src/AyonUsdResolver/cache tests/memcachedExpiryTest.cpp && ./a.out prints ok.
Permutation matrix: every combination of the four variables (3×4×4×4), on both the single-lookup and the prewarm path, × 6 URI kinds. That is 384 configs and 19,896 assertions, checked against an independent Python oracle using the server's own counters. All resolver assertions passed: stored keys, expiry measured from set time, hits, AYON calls, returned values, exact delete_hits on ClearCache, and no flushes.
Harness from tests(bench): add the resolver configuration benchmark harness #100, 181-URI shot: the cold, degraded and no-cache cells are unchanged. A warm 24-shot run went from 258 ms to 92 ms. Without the miss marker it was 799 ms, because 15 dangling references re-asked AYON every time.
This port: our branch rebased onto the current branch head (which includes 5c2c1fe). The top of the stack (up/unmapped-root-miss-marker) was built for Houdini 21.0.700 with memcached enabled and smoke-tested against production AYON: 58 sets cold, then 58 hits and 0 sets warm, with paths and prim counts identical to our production build. This PR's head was also built on its own.
Review fixes (Copilot, 2026-11-02): e59d68d empty-value marker (moved here from up/unmapped-root-miss-marker), a8af2e6 no PreCache entry for a marked miss, d4fff83ClearCache skips bypassed classes, 059252a marker deletes only while the key still holds the marker, incl. DeleteFromCache without a local entry. Checked in one process against a scratch memcached, with "another client" and "a publish" played by writing memcached directly. All 8 checks pass on this head (standalone OpenUSD 25.05). Our previous build fails exactly the 4 that the review describes: same-process publish, DeleteFromCache of a marker it only read, ClearCache keeping a replaced positive, ClearCache leaving a bypassed latest key. The parity smoke is unchanged: 58 sets cold, 58 hits / 0 sets warm, same paths and prim counts.
Further fixes from an independent review: 8cdab19 only an integer version is immutable (a version-less URI used to be cached forever), a756efb the marker is written with memcached_add so it never overwrites a path another process stored meanwhile, e2a70f2 URIs over memcached's 250-byte key limit are skipped instead of failing every get/set, f234403 the rootless conversion matches whole path segments and the longest root (/mnt/work no longer matches /mnt/work2/...), 7588bd8CommonCache inserts take an exclusive lock (an older data race, not memcached-specific). tests/memcachedExpiryTest.cpp covers the new classification.
Rollout note: with immutable keys no longer expiring, a hero whose path moves (deleted, re-templated) is bounded by the hero TTL. In our data the hero path is version-free (.../hero/<product>.<ext>) for every template except render, so republishing doesn't change the cached path.
…er flushes shared cache
- AYON_MEMCACHED_EXPIRE_SECONDS (default 0 = never expire) replaces the hard-coded 1 h TTL
- AYON_MEMCACHED_LATEST_EXPIRE_SECONDS for version=latest/latestdone URIs
(default -1 = bypass memcached for both get and set; 0 never; >0 seconds)
- clamp to memcached's 30 day relative limit, invalid values fall back with TF_WARN
- ClearCache() clears in-process caches only; drop unused MemcachedHandler::flushAll
- pure helpers in memcachedExpiry.h with a standalone test in tests/
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hero is mutable (a republish re-points it in place), integer versions are
not. Classify URIs as immutable/hero/latest with one TTL each; new
AYON_MEMCACHED_HERO_EXPIRE_SECONDS defaults to 3600. ClearCache now
deletes this session's hero/latest keys from memcached (never flush).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ClearCache and the invalidation path now delete keys, and a failed
delete leaves a stale entry behind. TF_DEBUG made it invisible in
production; log it through the same warning as get/set.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add AYON_MEMCACHED_MISS_EXPIRE_SECONDS (default 60, -1 off, 0 refused).
A failed resolve (uri, "") writes a reserved marker under the URI key;
readers treat it as a known miss without calling AYON and never return it
as a path. ClearCache deletes the markers this process saw.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With LATEST=30 and MISS=60 a missing latest URI was remembered for 60 s,
longer than a found one. Use min(class, miss) when the class TTL is
positive; the miss TTL when the class never expires.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Negative-cache handling can preserve failed resolutions beyond marker expiry, cause older clients to return miss markers as resolved paths, and incorrectly delete valid shared cache entries.
Adds configurable expiry and negative caching to the resolver’s shared memcached layer, while replacing site-wide cache flushing with targeted invalidation.
Changes:
Adds per-version-class expiry settings, validation, and standalone helper tests.
Introduces short-lived miss markers in single and batch resolution paths.
Replaces flush_all with targeted deletion and adds warnings for delete failures.
File
Description
tests/memcachedExpiryTest.cpp
Tests URI classification, expiry parsing, and miss TTL selection.
Builds without miss markers returned the \x01ayon-resolver-miss marker as a resolved path, so a URI
one build had recorded as missing broke the stage open in the other. An empty value reads as a plain
miss there (they ask AYON and get the right answer). The marker string stays the in-process sentinel;
only MemcachedHandler maps it to and from the empty wire value. libmemcached returns an empty value
as NULL + SUCCESS from get.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YRNAzpFt5VwUwBTHRbRQRm
The process that wrote a miss marker also cached the failed resolve in PreCache, whose hits return
before memcached is checked. It kept returning the empty path after the marker expired or was
deleted, hiding a later publish until its cache was cleared. A miss that got a marker is now only in
memcached, like a miss read from a marker. Without a marker (memcached off, miss caching disabled,
write failed) the in-process entry stays as before, so repeated resolves of a missing URI still do
not each call AYON.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YRNAzpFt5VwUwBTHRbRQRm
With a class TTL of -1 (`latest` by default) the resolver never reads or writes memcached for those
URIs, but ClearCache still deleted their keys: wasted round trips (each can hit the timeout) and it
could evict an entry another client wrote with that class enabled.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YRNAzpFt5VwUwBTHRbRQRm
ClearCache deleted every key this process had ever seen as a miss. After a publish that key can
hold a real path (written by this process or another), and the unconditional delete evicted it,
including integer-version entries the README says survive ClearCache. DeleteFromCache(uri) had the
opposite problem: both removeCachedObject overloads need a local asset before touching memcached,
and a known miss has none, so its marker stayed until the TTL.
_DeleteMissMarker reads the key and deletes it only if it still holds the marker. ClearCache uses
it for tracked misses; both removeCachedObject overloads call it when no local entry matched, after
releasing their cache locks. memcached has no conditional delete, so a path written between the get
and the delete is still dropped: one extra AYON lookup, never a wrong path.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YRNAzpFt5VwUwBTHRbRQRm
A URI without a version, or with `*` or an unknown value, was classed immutable and cached with no
expiry. The server applies no version filter for those (get_version_conditions returns []), so the
answer is any matching version and changes as versions are published; caching it forever pinned
whichever one came first. Such URIs now get the latest class (bypassed by default).
Values are normalised as the server does: trimmed, lowercased, one leading `v` dropped, so `vhero`
and `vlatest` are hero and latest instead of immutable.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YRNAzpFt5VwUwBTHRbRQRm
Between a process's failed AYON lookup and its marker write, another process can resolve the URI
(after a publish) and store the path. memcached_set then replaced that path with the marker and every
client saw a miss until the marker expired. memcached_add stores the marker only when the key is
empty; NOTSTORED means memcached already holds the answer, so the miss is not kept in-process either.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YRNAzpFt5VwUwBTHRbRQRm
memcached keys are at most 250 bytes. A longer URI failed every get and set with a warning and was
never cached anyway; get/set/add now skip it quietly (delete reports it as absent).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YRNAzpFt5VwUwBTHRbRQRm
_ToRootlessPath took the first root (in unordered_map order) that was a plain string prefix, so
with roots /mnt/work and /mnt/work2 the path /mnt/work2/a could be stored as {root[work]}2/a, and a
nested root could lose to its parent. Another site then re-roots it to a wrong path. With integer
versions no longer expiring, such an entry would stay wrong indefinitely. A root now matches only at
a path separator (or the end), and the longest matching root wins.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YRNAzpFt5VwUwBTHRbRQRm
getAsset inserted non-AYON paths into m_CommonCache while holding only a shared lock, so two
threads resolving relative or absolute paths at once could modify the unordered_set concurrently.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YRNAzpFt5VwUwBTHRbRQRm
@antirotor these are ready for review. Suggested order: #104 → #105 → #106 (all three are based on enhancement/featuriing-memcached); ynput/ayon-cpp-api#60 is independent. They've been running in our staging studio as part of our fork's v1.2.0-sas6 release without issues.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Malformed AYON entity data is treated as a confirmed miss, causing shared miss markers to suppress retries until their TTL expires; markers should be written only for explicitly confirmed misses.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Malformed entity data is incorrectly cached as a confirmed miss
When AYON returns malformed entity data, getAssetIdent() catches the JSON exception after setting the URI and returns (uri, ""), which this condition treats as a confirmed miss. This writes a shared miss marker and suppresses retries for the marker TTL; the same issue occurs in batchWarm() at lines 381–384. Propagate a distinct confirmed-miss status through the API and write markers only for that status.
Integration tests. Its remaining scenarios are added after 3, 4 and 6 are in, because they fail without them
#108 and #109 should follow this PR straight away, so the base branch does not carry those bugs for long. #105 and #106 do not need any changes for this: each already contains the earlier PRs' commits, and their diffs shrink as those merge.
Use a regular merge, not a squash, for #104, #105, #106, #108, #109 and #110. They share commits, so squashing one would make the later ones conflict. If ynput/ayon-cpp-api#61 is squashed, #109's submodule pointer needs updating before it merges.
Tested: I merged 2–7 in this order onto 17ae5ce with no conflicts. The result has the same tree (4ce0fdf) as the build I ran against a live AYON server: 123 scenarios passed on memcached and Dragonfly, plus 2 expected failures for the site-roots case #106 leaves open. The tested build includes ynput/ayon-cpp-api#61's commit.
Still open after all of these: a working key with a failed site-roots fetch still returns {root[...]} paths, as #106 notes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Makes the memcached cache's expiry configurable per URI class. Also stops
ClearCache()from wiping the shared cache, and adds a short-lived negative cache for lookups AYON can't resolve.We have run this stack in production since 2026-10-27, on Houdini 21.0.559/700/792, Houdini 22.0.368, Maya 2026.2 and standalone OpenUSD 25.05, with one memcached per region in four regions.
Why
memcachedHandler.h,expireSeconds = 3600). In production, 80–95 % of what we wrote expired, more than half of it never read, and every session after a break started cold. Integer versions never change, so they don't need to expire at all.ClearCache()ranflush_all. One artist pressing Houdini's "clear resolver cache" emptied the cache for the whole site: 7–23 flushes per site in 37 days.Changelog
AYON_MEMCACHED_EXPIRE_SECONDS0(never)0,>0sAYON_MEMCACHED_HERO_EXPIRE_SECONDSversion=hero3600-1bypass,0,>0sAYON_MEMCACHED_LATEST_EXPIRE_SECONDSversion=latest/latestdone-1(never touches memcached)-1,0,>0sAYON_MEMCACHED_MISS_EXPIRE_SECONDS60-1off,>0s (0refused)versionquery value, normalised like the server does (trimmed, lowercased, one leadingvdropped). Only an integer is immutable. A missing version,*or any other value gets the latest class: the server then matches any version, so there is no stable answer to cache. Precedence is Latest > Hero > Immutable.TF_WARN.memcached get failed: SUCCESSwhen they read a marker; harmless, and only while old and new builds share a cache.)ClearCache()clears the in-process caches. It deletes only this process's hero and latest keys from memcached (skipping a class set to-1, which never wrote them) and leaves integer keys alone.flushAllis removed.ClearCache()for the misses this process saw,DeleteFromCache(uri)for one URI) remove a key only while it still holds the marker, so a path stored in the meantime is kept.5c2c1fe("fix possible deadlock").s_memcachedMutexis never held together with the cache locks, including in the new key-delete loop inClearCache.With the defaults, no env var needs setting.
Approval
@antirotor @BigRoy
Linked issues/branches
enhancement/featuriing-memcached(Memcached support #82)up/memcached-mgetandup/unmapped-root-miss-markerType of Change
Additional info
Testing
tests/memcachedExpiryTest.cpp(standalone):g++ -std=c++17 -I src/AyonUsdResolver/cache tests/memcachedExpiryTest.cpp && ./a.outprintsok.delete_hitsonClearCache, and no flushes.5c2c1fe). The top of the stack (up/unmapped-root-miss-marker) was built for Houdini 21.0.700 with memcached enabled and smoke-tested against production AYON: 58 sets cold, then 58 hits and 0 sets warm, with paths and prim counts identical to our production build. This PR's head was also built on its own.Review fixes (Copilot, 2026-11-02):
e59d68dempty-value marker (moved here fromup/unmapped-root-miss-marker),a8af2e6no PreCache entry for a marked miss,d4fff83ClearCacheskips bypassed classes,059252amarker deletes only while the key still holds the marker, incl.DeleteFromCachewithout a local entry. Checked in one process against a scratch memcached, with "another client" and "a publish" played by writing memcached directly. All 8 checks pass on this head (standalone OpenUSD 25.05). Our previous build fails exactly the 4 that the review describes: same-process publish,DeleteFromCacheof a marker it only read,ClearCachekeeping a replaced positive,ClearCacheleaving a bypassedlatestkey. The parity smoke is unchanged: 58 sets cold, 58 hits / 0 sets warm, same paths and prim counts.Further fixes from an independent review:
8cdab19only an integer version is immutable (a version-less URI used to be cached forever),a756efbthe marker is written withmemcached_addso it never overwrites a path another process stored meanwhile,e2a70f2URIs over memcached's 250-byte key limit are skipped instead of failing every get/set,f234403the rootless conversion matches whole path segments and the longest root (/mnt/workno longer matches/mnt/work2/...),7588bd8CommonCacheinserts take an exclusive lock (an older data race, not memcached-specific).tests/memcachedExpiryTest.cppcovers the new classification.Rollout note: with immutable keys no longer expiring, a hero whose path moves (deleted, re-templated) is bounded by the hero TTL. In our data the hero path is version-free (
.../hero/<product>.<ext>) for every template exceptrender, so republishing doesn't change the cached path.🤖 Generated with Claude Code