clinton has asked for the wisdom of the Perl Monks concerning the following question:

Brethren, some advice please...

I've written a permissions module which is the ultimate in flexbility in inherited permissions, so for instance:-

You will understand that this is flexible, but slow. It needs to retrieve the permissions for all combinations of John and his parent and groups, and image X and its parent and groups.

So when requesting the inherited permissions for John/X, it finds all combinations and asks for the inherited permissions of each, and caches the result in itself. (Which of course means that every previously checked combination is cached as well.)

This is all well and good, but it raises issues:

Wisdom greatly received.

Replies are listed 'Best First'.
Re: Efficient cross server caching
by Aristotle (Chancellor) on Jan 30, 2006 at 23:48 UTC

    “There are only two hard things in Computer Science: cache invalidation and naming things.” —Phil Karlton

    The simplest approach in your case would be to only keep a local cache on each machine and to invalidate all caches whenever any permission changes. Depending on how frequently you run the same queries and how rarely permissions change in relation to that, this may well be plenty good enough. Beyond that, things can get arbitrarily complex… go there only if real-world performance numbers tell you that you need to.

    Makeshifts last the longest.

Re: Efficient cross server caching
by srdst13 (Pilgrim) on Jan 30, 2006 at 23:36 UTC
Re: Efficient cross server caching
by samtregar (Abbot) on Jan 30, 2006 at 23:46 UTC
    Krang deals with very similar problems using special pre-computed caching tables in a MySQL database. These tables store the computed permissions for each object, taking into account inherited permissions from the category tree. When permissions change the cache tables are recomputed - this slows updates but provides good read performance.

    -sam

Re: Efficient cross server caching
by clinton (Priest) on Jan 31, 2006 at 01:32 UTC
    Thank you

    All three of the above raise very good points. I had never heard of memcached and it sounds excellent - will look into it futher.

    The other two comments brought me back to the real world: In any site, chances are that, even if you have many people creating new groups (as would be the case with my current project), it is still tiny in comparison with the number of people doing reads.

    Hence the need for instant cache updates is reduced.

    Many thanks for the suggestions - I will sleep easier tonight.