quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Stearns <jps-red...@savagebeast.com>
Subject Re: [mod_python] Using shared memory to do global persistence
Date Fri, 27 Jun 2003 04:10:52 GMT
This code isn't thread-safe. It's entirely possible that
	cache['foo'] = 'bar'
will raise an exception.

Of course, other similar errors are possible when deleting entries.

Making a dict in shared memory is easy, but making something that can 
be used safely by non-experts is harder. You and I might know how to 
use this safely, but it will certainly be a source of trouble and 
questions from newcomers. The same folks who are having trouble storing 
sessions in a database will fall prey to a new kind of subtle bug.

-jeff

On Thursday, June 26, 2003, at 04:58 PM, Jack Diederich wrote:

> I think your use of dicts is dead on, something like:
> def do_calc():
>   cache = mod_python.shared
>   if ('foo' not in cache):
>     cache['foo'] = 'bar'
>   return cache['foo']
>
> As I mentioned during the long thread on what frameworks
> should do, we could add two dicts to mod_python,
> mod_python.page_cache # caching dict created per-request
> mod_python.perm_cache # cache valid accross all processes for ever
>
> perm_cache could actually lie and just keep the last X least
> recently used entries, but the main idea is that it is long
> lasting and valid accross all processes.  An intermediate
> mod_python.proc_cache that is similarly 'permenent' for the
> life of the process, but only caches values locally to the
> current process might be useful in a pure-forking server
> because it doesn't have to worry about locking.  If you are
> threading you have to do locking anyway, so perm_cache is
> more useful.
>
> -jack


Mime
View raw message