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
cache: compareAndSwap and saveMany don't refuse '' and '0' like save does #15707
The cache does not apply one rule for which values it stores:
Cache::compareAndSwap() (packages/cache/src/Cache.php:240-245) has no data check, unlike save() and saveWithLease(), which refuse '' and '0'.
On Memory, compareAndSwap('k', '', $version) calls save(), which refuses it, so it throws Unavailable('Unable to save cache snapshot') (Adapter/Memory.php:33-34). A refused value is reported as an outage.
On Redis and Redis\Multiplexing, the CAS script stores '', and load() returns it (Adapter/Redis/Versioned.php:104-118).
saveMany() stores '' and '0' field values (Adapter/Redis.php:205-211, Adapter/Redis/Multiplexing.php:278-285, Adapter/RedisCluster.php:146-149), while save() refuses them.
No caller passes '' or '0' through these paths today. utopia-php/database's mutation records are always ['owners' => …].
Fix: return false for '' and '0' in Cache::compareAndSwap(), as saveWithLease() does. Either skip ''/'0' fields in saveMany(), or document that fields are stored as given. Add tests for both.
Staging run showing where saveMany() storing '0' is visible.
On staging fra (cloud-fra1-stg), while testing appwrite-labs/cloud#7621 (utopia-php/cache 8.0.0), the list cache cached the total "0" for an empty table through saveMany(), even though save() refuses '0':
ListCache::save() writes every field with Cache::saveMany() (src/Appwrite/Utopia/Cache/ListCache.php), so the total of an empty list is stored as "0".
The list action skips saving the empty row list (if ($documents !== []) in Databases/Collections/Documents/XList.php), so the rows aren't cached.
Steps (TablesDB rows list, ttl=600):
List an empty table: total: 0, X-Appwrite-Cache: miss.
PASS list empty ttl=600 rows has e1 (empty never cached) 200 [e1] cache=miss
NOTE list empty ttl=600 total (cached '0', row writes don't purge) 0 cache=hit
The same happened on the build before #15704 and the build after it, so 8.0.0 didn't cause it. The list behaviour is tracked in #15718. If saveMany() gets the same ''/'0' guard as save(), it would stop caching that "0" total, so #15718's fix has to be decided together with this one.
Hi @ArnabChatterjee20k, I'd like to work on this. Plan: in Cache::compareAndSwap() (packages/cache/src/Cache.php), return false for '' and '0' before calling the adapter, as saveWithLease() does. Then Memory doesn't report a refused value as Unavailable, and Redis doesn't store it. In saveMany() on Redis, Redis\Multiplexing and RedisCluster, skip '' and '0' fields so it matches save(). Given your staging note on the cached "0" total, skipping looks safer than documenting. Tests: unit tests per adapter for CAS refusing both values, and saveMany() leaving them out while storing the other fields. Could you assign it to me?
Activity
ArnabChatterjee20k commentedon Nov 17, 2026
Staging run showing where
saveMany()storing'0'is visible.On staging fra (
cloud-fra1-stg), while testing appwrite-labs/cloud#7621 (utopia-php/cache8.0.0), the list cache cached the total"0"for an empty table throughsaveMany(), even thoughsave()refuses'0':ListCache::save()writes every field withCache::saveMany()(src/Appwrite/Utopia/Cache/ListCache.php), so the total of an empty list is stored as"0".if ($documents !== [])inDatabases/Collections/Documents/XList.php), so the rows aren't cached.Steps (TablesDB rows list,
ttl=600):total: 0,X-Appwrite-Cache: miss.e1.rows: ["e1"](read fresh),total: 0(cached),X-Appwrite-Cache: hit.The same happened on the build before #15704 and the build after it, so 8.0.0 didn't cause it. The list behaviour is tracked in #15718. If
saveMany()gets the same''/'0'guard assave(), it would stop caching that"0"total, so #15718's fix has to be decided together with this one.Full staging results: https://github.com/appwrite-labs/cloud/pull/7621 (Tests → Staging).
rahulsjha commentedon Nov 18, 2026
Hi @ArnabChatterjee20k, I'd like to work on this. Plan: in
Cache::compareAndSwap()(packages/cache/src/Cache.php), returnfalsefor''and'0'before calling the adapter, assaveWithLease()does. Then Memory doesn't report a refused value asUnavailable, and Redis doesn't store it. InsaveMany()on Redis, Redis\Multiplexing and RedisCluster, skip''and'0'fields so it matchessave(). Given your staging note on the cached"0"total, skipping looks safer than documenting. Tests: unit tests per adapter for CAS refusing both values, andsaveMany()leaving them out while storing the other fields. Could you assign it to me?