weavejester/clj-aws-s3 — pull request #28 by neatonk (2013-04-29 16:01:19+00:00)
Title: Added :session-token and :client-id to enable temporary session credentials

AWS session credentials include a session token so which is now accepted in your `cred` map as `:session-token`.

Because `s3-client` uses `memoize` to cache clients and temporary session credentials are... temporary, it was necessary to improve the client caching strategy to avoid creating a new client every time the session credentials expire and get refreshed. See #15 for the full rationale.

The caching strategy used in this pull request, behaves just like the `memoize` solution, unless a `:client-id` is included in the `cred` map. The client-id is used as the cache key instead of the map itself so that only one client is cached for each client-id. When the client is cached, the arguments used to create it are cached as well and a new client is created when the arguments change.

This solution should continue to avoid issue #3 except in a very limited case where the same client-id is used on multiple threads and the first client gets booted from the cache and GC'd too soon. A better solution may be to return a reference to the client used for each request in the response so the caller can hold onto it until it's ok for the client to be GC'd.