28 Jun '14, 5am

AWS.memoize #jawsug #cloudschool

Note: Memoization is currently only supported for APIs which inherit from the "Resource" class; other APIs are unaffected by the status of memoization. Enables memoization for the current thread, within a block. Memoization lets you avoid making multiple requests for the same data by reusing the responses which have already been received. For example, consider the following code to get the most recently launched EC2 instance: latest = ec2 . instances . sort_by ( & :launch_time ) . last The above code would make N+1 requests (where N is the number of instances in the account); iterating the collection of instances is one request, and Enumerable#sort_by calls AWS::EC2::Instance#launch_time for each instance, causing another request per instance. We can rewrite the code as follows to make only one request: latest = AWS . memoize do ec2 . instances . sort_by ( & :launch_time )...

Full article: http://www.rubydoc.info/github/aws/aws-sdk-ruby/AWS.memoize