Roman Levytskyi
06/12/2025, 9:34 AMpanic: gcache: Cache size <= 0
While in the docs it is:
You can turn off caching completely by setting compile.cacheSize configuration to 0. This would have a small performance hit but depending on your use case it could be negligible.
This happens when we set the property to 0
in helmoguzhan
Roman Levytskyi
06/12/2025, 9:48 AM0.44.0
Roman Levytskyi
06/12/2025, 9:48 AMoguzhan
compile.cacheDuration
to really low value instead.Roman Levytskyi
06/12/2025, 10:49 AMRoman Levytskyi
06/12/2025, 10:54 AMoguzhan
compile.cacheDuration
.
After a compiled policy gets evicted from the cache, the next time it is needed it's retrieved from the database and cached again for the duration of compile.cacheDuration
.
In summary, setting the compile.cacheDuration
to 60s
does what you have described.Roman Levytskyi
06/12/2025, 11:11 AMcacheDuration
?Roman Levytskyi
06/12/2025, 11:13 AMRoman Levytskyi
06/12/2025, 11:14 AMRoman Levytskyi
06/12/2025, 11:20 AMoguzhan
in our case what we noticed is that policies althoug they have 60s cache storage, sometimes cache is out of date if the request hits another instance.Since each cerbos instance has its own in-memory cache, a specific policy could be cached at
t=0s
for one instance and t=10s
for another instance.
Let's say you've updated that policy in the database at t=20s
, this means the first instance will fetch the new policy at t=60s
, while the second instance will fetch it at t=70s
.
This means if another request comes to second instance at t=65s
as an example, the old policy will be used for the result.oguzhan
AddOrUpdate
RPC is called to update a policy in one specific PDP instance, the in-memory cache is updated instantly for that PDP. Only the other instances need wait for the cache duration for a specific compiled policy.Roman Levytskyi
06/12/2025, 11:25 AMRoman Levytskyi
06/12/2025, 11:26 AMoguzhan
Roman Levytskyi
06/12/2025, 11:27 AMPaulo Henrique Cardoso
06/13/2025, 1:05 PMv0.44.0
and postgres db
any progress here worth sharing?
additionally, about the Admin API reload store call:
is this bit of info correct? is postgres a "reloadable storage driver"?oguzhan
postgres
) are reloadable.Paulo Henrique Cardoso
06/13/2025, 1:10 PMoguzhan
cerbos v0.40.0
which doesn't have this issue.
If you'd like to keep using the latest version, you could call reload store RPC of each Cerbos instance to clear the cache. This also works.
GitHub issue to track: cerbos/cerbos#2601Paulo Henrique Cardoso
06/13/2025, 1:27 PMA
and B
, both with policy X
cached.
PDP A
received the admin API call to create policy Y
PDP B
never had used policy Y
, therefore it isn't cached yet
if I call the reload store on B
, would it fetch policy X
and Y
?oguzhan
Y
is newly introduced, PDP B
will fetch it as usual when a checkResources
or planResources
call arrives. No reload store call is necessary for this case.
If you'd update the policy X
via Admin API of the PDP A
, then you'd need to call reload store in PDP B
.
But to answer your question regarding reload store, the reload store purges everything in the cache and this means the PDP must hit the underlying storage after a call to the checkResources
or planResources
.Paulo Henrique Cardoso
06/13/2025, 1:40 PMB
always has it's cache up to date, I'd have to call plan
or check
to every policy stored on db
only after that a reload store would be relevantoguzhan
check
and plan
bit.
Every time a policy is added/deleted/updated
, calling reload store RPC on all instances is enough to remedy this issue.Paulo Henrique Cardoso
06/13/2025, 1:51 PMcheck
or planResources
arrivePaulo Henrique Cardoso
06/13/2025, 3:05 PMoguzhan
Roman Levytskyi
06/16/2025, 4:24 PM