0

Note: Be sure to locally cache a copy of the APIs you're using. Doing so saves a round-trip to Google servers on every run. You can do this by serializing the returned Google::APIClient::API object to an appropriate location. Check the sample code for more details.

For serializing Objects I believe it's as simple as Marshal. I've looked at the sample code they've provided but I don't see how this is done. In a scalable Rails server would it be best to somehow have the API loaded when the Rails server starts and have it be usable by countless clients from the Rails system memory? I believe to marshal and unmarshal it into the DB would be a bad idea.

I need to write it in such a way that the discovered API request doesn't run for each user instance and call. I'm thinking an initializer would be nice. I've search for a Rails configuration for google-api-ruby-client. But there doesn't seem to be a site-wide model for this. Each example loads and calls everything each execution.

The best case answer would be an initializer that allows me to load the API once on server starts and to be able to call it from many different user credentials which are already saved.

Here's one such API discovery I'll be using:

Google::APIClient.new(
  application_name: "My App Name", application_version: "1.0.0"
).discovered_api('plusDomains')
6ft Dan
  • 2,365
  • 1
  • 33
  • 46

1 Answers1

1

Caching is done automatically.

Apparently the documentation is out of sync.

In the sample code, there is this comment:

# Initialize API Service.
#
# Note: the client library automatically creates a cache file for discovery
# documents, to avoid calling the discovery service on every invocation.
# To set this to an ActiveSupport cache store, use the :cache_store parameter
# (or, alternatively, set it to nil if you want to disable caching).

Digging into the client itself, caching is indeed handled automatically and uses local file storage by default.

Substantial
  • 6,684
  • 2
  • 31
  • 40