> I don't think Cache::Cache has enough logic for an "atomic
> read-modify-write" in any of its modes to implement (for example) a
> web hit counter.  It has only "atomic write".  The "last write wins"
> strategy is fine for caching, but not for transacting, so I can see
> why Rob is a bit puzzled.

In his example code he was only doing atomic writes as well, so it should
work at least as well for his app as what he had before.

> It'd be nice if we could build a generic "atomic read-modify-write"

Maybe a get_for_update() method is what's needed.  It would block any other
process from doing a set() or a get_for_update() until the set() for that
key has completed.  It's still just advisory locking though, so if you
forget and use a regular get() for some data you later plan to set(), you
will not be getting atomic read-modify-write.  Maybe get() could be re-named
to get_read_only(), or set a flag that prevents saving the fetched data.
Most caching apps are happy with "last save wins" though, so I guess
anything like that would need to be optional.

- Perrin

Reply via email to