Closed realaravinth closed 3 years ago
It seems there's already a mechanism in place to do this job. A dummy entry is made right after bucket creation, who's expiry acts as a fallback to trigger execution of scheduled jobs.
https://github.com/mCaptcha/cache/blob/a1f9bcb247f4d2c6d85c902fdec3b1aeaf276ab1/src/bucket.rs#L232
I should work on simplifying the whole thing or at the very least document all hacks used.
Bucket's expiration callback is executed after the bucket is deleted. As a result, all jobs scheduled within the bucket are lost. This means, we could end up with stagnant values(visitor counts) in mcaptcha objects.
Timers are not persisted during
rdb
saves. So when cache is restored from disk, the above issue will happen. Rather than relying on timers execute jobs, use a safety object, upon who's expiry, the bucket's (callback runner) will be executed.