Skip to content

Instantly share code, notes, and snippets.

@toastdriven
Created June 3, 2014 02:28
Show Gist options
  • Save toastdriven/97dfc6e20842ec143007 to your computer and use it in GitHub Desktop.
Save toastdriven/97dfc6e20842ec143007 to your computer and use it in GitHub Desktop.
from boto.s3 import S3RegionInfo
from boto.s3.connection import S3Connection
import redis
class CachedS3Connection(S3Connection):
cache_conn = redis.StrictRedis()
def get_all_buckets(self, headers=None):
if self.cache_conn.exists('all_buckets'):
return self.cache_conn.lrange('all_buckets', 0, -1)
all_buckets = super(CachedS3Connection, self).get_all_buckets(headers=headers)
self.cached_conn.lpush(**all_buckets)
return all_buckets
us_east_1 = S3Region(
name='Yes Virginia, there is a cache.',
endpoint='s3.amazonaws.com',
connection_cls=CachedS2Connection
)
# Needs either env vars (best), a Boto config file (good) or to pass the ``aws_access_key_id/aws_secret_access_key`` params here (worst, don't do).
conn = us_east_1.connect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment