Axiom on the client and server, Client-side object caches was Re: Any ideas why Axiom is acting odd?

Robert Gravina <[email protected]> Mon, 3 Jul 2006 15:36:41 +0900
Newsgroups gmane.comp.python.quotient.dev
Message-ID <[email protected]>
[snip]

> The client can edit attributes and send them back, and since I have  
> the storeID I can load the original Item and alter it's attributes.

Actually, what I'm thinking of doing is creating some kind of client  
side object cache.

1) In the general case, when an Item is sent to the client from the  
server (it should also be a Copyable), getStateToCopy method replaces  
all references with storeIDs, keeping the attribute names the same.  
If you know the references are going to be needed, make them  
Copyables too and just send them instead.

e.g. server side
MyItem(Item, pb.Copyable)
	books(self)
		return self.store.query.....
	getStateToCopy(self):
		d = {}
		d["books"] = self.books()
RemoteMyItem(pb.RemoteCopy)
	books[]

2) Whenever the client wants to access an object reference, it needs  
to check if the reference is an int or not (i.e. a storeID) and if so  
ask the cache for the object. It can then replace the storeID with  
the object itself.  The cache is a pb.Cacheable which contains a  
dictionary indexed by storeID. If the cache misses, it should get the  
object from the server, add it to the cache. When objects are updated  
on the client, the client caches can be notified also.

e.g.
import types
if type(myitem.books) is types.IntType:
	myitem.books = cache.get(myitem.books)
for book in myitem.books:
	print book.name

Maybe a better idea than using an int for the storeID (since the  
attribute might actually *be* an int) is to use a placeholder object  
like:

class StoreID(object):
	storeID

so that we can...

if type(myitem.books) is StoreID:

I might be able to make that code more natural by altering the  
__gettattr__ and __setattr__ methods on the dict in the cache, and on  
MyItem so that it will do this "behind the scenes". Also I haven't  
dealt with Deferred and callbacks in the pseudcode above neither.

Anyway, have I totally lost the plot here? I sometimes feel like I'm  
the only person who's trying to do something like this. Have I just  
misunderstood how to use Twisted PB?

(not sure if this is how you rename a thread, but I did it manually  
in the subject of this mail)

Robert