Permalink
Browse files

Added use_locks flag to S3 cache creation

  • Loading branch information...
1 parent fcb883d commit 1780eea8c10a5eadb5a4be8c7fdce9426e8d8dcd @migurski migurski committed Dec 3, 2012
Showing with 20 additions and 2 deletions.
  1. +8 −0 API.html
  2. +1 −1 TileStache/Config.py
  3. +11 −1 TileStache/S3.py
View
@@ -672,6 +672,14 @@ <h4><a id="s3-cache" name="s3-cache">S3</a> <a href="#s3-cache" class="permalink
Required secret access key for your S3 account. You can find this under “Security
Credentials” at your <a href="http://aws.amazon.com/account/">AWS account page</a>.
</dd>
+
+ <dt>use_locks</dt>
+ <dd>
+ Optional boolean flag for whether to use the locking feature on S3.
+ <samp>True</samp> by default. A good reason to set this to
+ <samp>false</samp> would be the additional price and time required for each
+ lock set in S3.
+ </dd>
</dl>
<p>
View
@@ -299,7 +299,7 @@ def add_kwargs(*keys):
add_kwargs('servers', 'lifespan', 'revision')
elif _class is Caches.S3.Cache:
- add_kwargs('bucket', 'access', 'secret')
+ add_kwargs('bucket', 'access', 'secret', 'use_locks')
else:
raise Exception('Unknown cache: %s' % cache_dict['name'])
View
@@ -23,6 +23,11 @@
secret
Required secret access key for your S3 account.
+ use_locks
+ Optional boolean flag for whether to use the locking feature on S3.
+ True by default. A good reason to set this to false would be the
+ additional price and time required for each lock set in S3.
+
Access and secret keys are under "Security Credentials" at your AWS account page:
http://aws.amazon.com/account/
"""
@@ -50,14 +55,19 @@ def tile_key(layer, coord, format):
class Cache:
"""
"""
- def __init__(self, bucket, access, secret):
+ def __init__(self, bucket, access, secret, use_locks=True):
self.bucket = S3Bucket(S3Connection(access, secret), bucket)
+ self.use_locks = bool(use_locks)
def lock(self, layer, coord, format):
""" Acquire a cache lock for this tile.
Returns nothing, but blocks until the lock has been acquired.
+ Does nothing and returns immediately is `use_locks` is false.
"""
+ if not self.use_locks:
+ return
+
key_name = tile_key(layer, coord, format)
due = _time() + layer.stale_lock_timeout

0 comments on commit 1780eea

Please sign in to comment.