Got it. The latter approach makes sense.<div><br></div><div>Thank you</div><div>Jacek<br><br><div class="gmail_quote">On Mon, Mar 5, 2012 at 12:45 PM, Phil Mayers <span dir="ltr">&lt;<a href="mailto:p.mayers@imperial.ac.uk">p.mayers@imperial.ac.uk</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 05/03/12 15:19, Jacek Furmankiewicz wrote:<br>
&gt; Hm, I would prefer to avoid that.<br>
&gt;<br>
&gt; In my case, the cost of creating a new Resource is high (since it needs<br>
&gt; to parse all the URLs it can dispatch to for all the REST services),<br>
&gt; therefore I would prefer to cache a single ReadOnlyResource vs<br>
&gt; AdminResource (as an example)<br>
<br>
</div>If you search the archives, you will find discussions on this.<br>
<br>
The general conclusion was: Resource objects should be lightweight and<br>
fast. If you&#39;ve got expensive stuff, pre-computer / cache / share /<br>
whatever, and make your Resource objects talk to the cache.<br>
<div class="im"><br>
&gt; and just serve one or the other.<br>
<br>
</div>So? Do that:<br>
<br>
avatars = {}<br>
<br>
class MyRealm:<br>
   def requestAvatar(...):<br>
<br>
     if is_admin(avatarId):<br>
       if not &#39;admin&#39; in avatars:<br>
          avatars[&#39;admin&#39;] = MyAdmin()<br>
       return avatars[&#39;admin&#39;], ...<br>
<br>
Of course, you&#39;ll be re-using the same avatar for all admins, and won&#39;t<br>
be able to distinguish them, or access their usernames.<br>
<br>
Alternatively you might have a lightweight resource that just does<br>
simple authorization / logging, and passes render calls through to the<br>
heavyweight resource:<br>
<br>
class MyAdmin():<br>
   def render(...):<br>
     request.username = self.username<br>
     return CachedHeavyAdmin.render(request, ...)<br>
<br>
class MyRealm():<br>
   def requestAvatar(...):<br>
     if is_admin(avatarId):<br>
       r = MyAdmin()<br>
       r.username = avatarId<br>
       return r<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
_______________________________________________<br>
Twisted-web mailing list<br>
<a href="mailto:Twisted-web@twistedmatrix.com">Twisted-web@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web</a><br>
</div></div></blockquote></div><br></div>