[google-appengine] Re: memcache in remote api

2009-07-14 Thread Nick Johnson (Google)

Hi Ben,

Thanks for posting the guide. A few corrections:

On Mon, Jul 13, 2009 at 8:19 PM, Ben Nevileben.nev...@gmail.com wrote:

 So I finally decided I needed to figure out how to make it happen.
 Here's a recipe for anyone else who wants to be able to access
 memcache via remote_api:

 1. copy the contents of /google/appengine/ext/remote_api/handler.py
 into a new local file.  i called mine remote_api_handler.py.  then
 change your app.yaml to point to this new local file.

You don't need to copy the code - just create your own module that
imports the relevant parts of the handler module. That way, you'll
pick up any future code changes and bugfixes.


 2. add the following import to remote_api_handler.py:
 from google.appengine.api.memcache import memcache_service_pb

 3. in remote_api_handler.py, find the SERVICE_PB_MAP dictionary.  add
 the following as a new service:
    'memcache': {
      'Get': (memcache_service_pb.MemcacheGetRequest,
 memcache_service_pb.MemcacheGetResponse),
      'Delete': (memcache_service_pb.MemcacheDeleteRequest,
 memcache_service_pb.MemcacheDeleteResponse),
      'Increment': (memcache_service_pb.MemcacheIncrementRequest,
 memcache_service_pb.MemcacheIncrementResponse),
      'FlushAll': (memcache_service_pb.MemcacheFlushRequest,
 memcache_service_pb.MemcacheFlushResponse),
      'Stats': (memcache_service_pb.MemcacheStatsRequest,
 memcache_service_pb.MemcacheStatsResponse),
      'Set': (memcache_service_pb.MemcacheSetRequest,
 memcache_service_pb.MemcacheSetResponse),
    }

You can do this by copying and/or modifying that dictionary after
you've imported it, then subclassing the handler to use the modified
dictionary.


 4. run your tests to make sure you haven't introduced any errors into
 your code.  deploy onto your server.

 5. open /google/appengine/ext/remote_api/remote_api_stub.py.  In the
 ConfigureRemoteDatastore method, add the following two lines at the
 end:
  stub = RemoteStub(server, path)
  apiproxy_stub_map.apiproxy.RegisterStub('memcache', stub)

You can also simply add this to your own code, again avoiding the need
to modify the SDK or copy its code.


 (feel free to reimplement this in a less hacky way if you like... the
 method could be renamed to include datastore and memcache
 configuration.)

 6. launch your remote_api console. enjoy access to memcache!



 Hope that helps someone out.
 Ben

 




-- 
Nick Johnson, App Engine Developer Programs Engineer
Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration
Number: 368047

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: memcache in remote api

2009-07-13 Thread Ben Nevile

So I finally decided I needed to figure out how to make it happen.
Here's a recipe for anyone else who wants to be able to access
memcache via remote_api:

1. copy the contents of /google/appengine/ext/remote_api/handler.py
into a new local file.  i called mine remote_api_handler.py.  then
change your app.yaml to point to this new local file.

2. add the following import to remote_api_handler.py:
from google.appengine.api.memcache import memcache_service_pb

3. in remote_api_handler.py, find the SERVICE_PB_MAP dictionary.  add
the following as a new service:
'memcache': {
  'Get': (memcache_service_pb.MemcacheGetRequest,
memcache_service_pb.MemcacheGetResponse),
  'Delete': (memcache_service_pb.MemcacheDeleteRequest,
memcache_service_pb.MemcacheDeleteResponse),
  'Increment': (memcache_service_pb.MemcacheIncrementRequest,
memcache_service_pb.MemcacheIncrementResponse),
  'FlushAll': (memcache_service_pb.MemcacheFlushRequest,
memcache_service_pb.MemcacheFlushResponse),
  'Stats': (memcache_service_pb.MemcacheStatsRequest,
memcache_service_pb.MemcacheStatsResponse),
  'Set': (memcache_service_pb.MemcacheSetRequest,
memcache_service_pb.MemcacheSetResponse),
}

4. run your tests to make sure you haven't introduced any errors into
your code.  deploy onto your server.

5. open /google/appengine/ext/remote_api/remote_api_stub.py.  In the
ConfigureRemoteDatastore method, add the following two lines at the
end:
  stub = RemoteStub(server, path)
  apiproxy_stub_map.apiproxy.RegisterStub('memcache', stub)

(feel free to reimplement this in a less hacky way if you like... the
method could be renamed to include datastore and memcache
configuration.)

6. launch your remote_api console. enjoy access to memcache!



Hope that helps someone out.
Ben

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: memcache in remote api

2009-05-27 Thread Ben Nevile

Hi Nick,

Thanks for your reply.

Here's a typical use case for me.  I often have methods like this:


def facebook_user_cache_key(uid):
  return str(uid) + _fbuser

def get_facebook_user(uid):
  u = memcache.get(facebook_user_cache_key(uid))
  if u == None:
uid = int(uid)
u = FacebookUser.all().filter('uid = ',uid).get()
if not u:
  u = FacebookUser(uid=uid)
  u.put()
memcache.set(facebook_user_cache_key(uid),u)
  return u


and I often get support emails from users, and would often like to be
able to dive in to the remote api console and load up their entity by
typing in get_facebook_user(THEIR_UID).

this is a trivial example - in some of the apps I have several layers
of entity that need to be loaded.  I already have great convenience
methods for dealing with this process, but I can't use them in remote
api because they rely on memcache.  so either I implement a
dont_use_memcache param, or else I write parallel methods that don't
use memcache.

or, another even simpler use case -- sometimes I update an entity, and
then want to delete any affected cache.


but HEY, are you calling me not dedicated?  them's fighting words.
will break open the source.

Ben



On May 26, 4:31 pm, Nick Johnson (Google) nick.john...@google.com
wrote:
 Hi Ben,

 Out of curiosity, what's your use case for accessing Memcache over
 remote_api? The main reason we didn't support it automatically is
 because there didn't seem to be any obvious reason why you'd want to
 use Memcache remotely.

 Also, note that a dedicated user can actually add support for extra
 services to remote_api relatively easily. :)

 -Nick Johnson



 On Mon, May 25, 2009 at 10:17 PM, BenNevileben.nev...@gmail.com wrote:

  Just wanted to mention that I created a new issue requesting support
  for memcache in the remote api console.  I searched but didn't find
  any existing similar requests.

 http://code.google.com/p/googleappengine/issues/detail?id=1596

  Would be a big help.  If this is of interest to you, please give 'er a
  star.

  Ben
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: memcache in remote api

2009-05-26 Thread Nick Johnson (Google)

Hi Ben,

Out of curiosity, what's your use case for accessing Memcache over
remote_api? The main reason we didn't support it automatically is
because there didn't seem to be any obvious reason why you'd want to
use Memcache remotely.

Also, note that a dedicated user can actually add support for extra
services to remote_api relatively easily. :)

-Nick Johnson

On Mon, May 25, 2009 at 10:17 PM, Ben Nevile ben.nev...@gmail.com wrote:

 Just wanted to mention that I created a new issue requesting support
 for memcache in the remote api console.  I searched but didn't find
 any existing similar requests.

 http://code.google.com/p/googleappengine/issues/detail?id=1596


 Would be a big help.  If this is of interest to you, please give 'er a
 star.

 Ben
 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---