473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

sharing persisten cache between modules

Hi,
I´ve got a problem creating persistent cache, that would be shared
between modules. There a supermodule, which calls submodules. I´d like
submodules to use cache created in the supermodule. The only way I see
right now, is to pass it as function argument, but that would require a
change in API, which I´d prefer to avoid. Is this the only way?

Oct 23 '06 #1
6 1086
Bart Ogryczak wrote:
I´ve got a problem creating persistent cache, that would be shared
between modules. There a supermodule, which calls submodules. I´d like
submodules to use cache created in the supermodule. The only way I see
right now, is to pass it as function argument, but that would require a
change in API, which I´d prefer to avoid. Is this the only way?
does "module" mean Python module? why not just put the cache management
code in a module that's imported by any submodule that wants to use it ?

</F>

Oct 23 '06 #2

Fredrik Lundh wrote:
Bart Ogryczak wrote:
I´ve got a problem creating persistent cache, that would be shared
between modules. There a supermodule, which calls submodules. I´d like
submodules to use cache created in the supermodule. The only way I see
right now, is to pass it as function argument, but that would require a
change in API, which I´d prefer to avoid. Is this the only way?

does "module" mean Python module?
Yes it does.
why not just put the cache management
code in a module that's imported by any submodule that wants to use it ?
The problem is, that then it is not shared. If I do it like that, each
module has it´s own copy of the cache. Maybe I´m doing something
wrong. I´ve made a cache module, imported it in each of the
submodules. I don´t know how to make the data "static".

Oct 23 '06 #3
Bart Ogryczak wrote:
Fredrik Lundh wrote:
>>Bart Ogryczak wrote:

>>>I´ve got a problem creating persistent cache, that would be shared
between modules. There a supermodule, which calls submodules. I´d like
submodules to use cache created in the supermodule. The only way I see
right now, is to pass it as function argument, but that would require a
change in API, which I´d prefer to avoid. Is this the only way?

does "module" mean Python module?


Yes it does.

>>why not just put the cache management
code in a module that's imported by any submodule that wants to use it ?


The problem is, that then it is not shared. If I do it like that, each
module has it´s own copy of the cache. Maybe I´m doing something
wrong. I´ve made a cache module, imported it in each of the
submodules. I don´t know how to make the data "static".
No, it doesn't. At least, not if the cache is global to the module
that's imported by all the other ones.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Oct 23 '06 #4
Bart Ogryczak wrote:
>why not just put the cache management
code in a module that's imported by any submodule that wants to use it ?

The problem is, that then it is not shared. If I do it like that, each
module has it´s own copy of the cache.
nope. modules are shared, and all module-level objects are shared as
well. the code in a module is only executed when you import it the
first time; all further imports will get a reference to the same module
instance.
Maybe I´m doing something wrong. I´ve made a cache module, imported it in
each of the submodules.
that should work. how do you create the cache in the module, and how do
the individual modules access the cache?

</F>

Oct 23 '06 #5

Dennis Lee Bieber wrote:
f-i-* creates local names initially bound to the objects inside a
module, but any "assignment" to such a name later results in the name
being rebound to the new object -- disconnecting from the original.
Great! That was it. Thank you! :-)

Oct 24 '06 #6
Dennis Lee Bieber wrote:
On 23 Oct 2006 09:45:33 -0700, "Bart Ogryczak" <B.********@gmail.com>
declaimed the following in comp.lang.python:
>>The problem is, that then it is not shared. If I do it like that, each
module has it´s own copy of the cache. Maybe I´m doing something
wrong. I´ve made a cache module, imported it in each of the
submodules. I don´t know how to make the data "static".


Let me guess... You are using

from cache_module import *

to save having to qualify names with "cache_module."

f-i-* creates local names initially bound to the objects inside a
module, but any "assignment" to such a name later results in the name
being rebound to the new object -- disconnecting from the original.

import cache_module

cache_module.some_name = some_object

maintains the linkage that the name is inside the module, so all other
references that use cache_module.some_name will see the same object.
Note that you can also do

import cache_module_with_long_name as cm

and then qualify cm to get at the module's attributes, should you have
chosen to call your module something inappropriately long. This reduces
the typing still further.

always-looking-to-avoid-typos-ly y'rs - steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Oct 24 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vic | last post by:
Hi, Is there a mechanism within PHP for sharing data over multiple requests that are not tied to a specific session. I need to write a memory senstive cache in pure PHP. I have an application...
4
by: A-PK | last post by:
Hi, currently I am working on a project with several programmers. my problem is how could I separate one project into several small module and assign to my programmers. after all the coding is...
13
by: Selma_g | last post by:
Hi, I am wondering if the bufferpools and agent memory canbe shared within a EE UDB instance (running 7.2 AIX 5 now but going to V8.1). Our business model requires us to add about 1-2 db's per...
0
by: Bob Dankert | last post by:
I have a program that has an auto-update feature in that it check for new updates, and launches an update program when there is a new version. This update program ensures the process is closed...
4
by: Mat | last post by:
Hi, I've stumbled onto a problem when using the caching object in ASP.Net. I'm placing a static dataset to the cache as the data only changes once a day. Whilst writing to the cache I'm using...
1
by: Ale K. | last post by:
Hi, i'm designing an 3 tier application, and i got the following question, let's say that on my bussines layer i have an object Box that has inside an object ItemCollection , that can store many...
1
by: Terry Olsen | last post by:
What is the best practice for sharing variables across modules in the same project? I'm doing a console app with different modules for different functions (file i/o, sql commands, string...
4
by: pcaisse | last post by:
I'm having issues sharing global variables with Explorer. This problem probably has a simple answer (as with most newbie questions). The script.pl file: #!/usr/bin/perl -w use strict; use...
9
by: Peri | last post by:
Dear All, Is there a way in which 2 application can share a common memory location to access static data? Say for example I have a product master data that is available in a single place, and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.