fix redis caching issue

Copying the content from the previously closed PR below. Feel free to refactor the methods into more python standard way as you had indicated.


This PR is trying to address the following

When caching(redis) was enabled in registry config, docker push failed. On close inspection of the registry code, it is clear that methods like "stream_read", stream_write, exists, get_size are supposed to not use the cache and directly look at the store. And the other important point is the redis cache is only to be used for all the meta data small files but not the layers. Hence, get_content() and put_content() methods decorated by the lru_* methods are only invoked for non layer operations. On the other hand stream_* methods are only for the actual layers. I wish this was documented. Anyways, so since the current implementation was invoking get_content/put_content for stream_read/stream_write it was bringing the cache into play when involving layers and caused the failure. 

 get_size implemented head request instead of get since the swift client supports it. This helps is not retrieving the entire content but get the same headers as get. I think the boto/s3 driver does the same.

After the changes things are looking fine. I am looking forward to add some more optimizations that the current S3 driver has.


Giving some additional context for the docker push error with redis caching enabled.
Here is the specific error on docker push around pushing layer

File "/usr/local/lib/python2.7/dist-packages/docker_registry/images.py", line
236, in put_image_layer
store.stream_write(layer_path, sr)
File "/usr/local/lib/python2.7/dist-packages/docker_registry/drivers/swift.py
, line 73, in stream_write
self.put_content(path, fp, self.buffer_size)
File "/usr/local/lib/python2.7/dist-packages/docker_registry/core/lru.py", li
e 67, in wrapper
key = cache_key(key)
File "/usr/local/lib/python2.7/dist-packages/docker_registry/core/lru.py", li
e 59, in cache_key
return cache_prefix + key
TypeError: cannot concatenate 'str' and 'SocketReader' objects
2014-06-16 23:19:12,219 ERROR: Exception on /v1/images/511136ea3c5a64f264b78b54
3614aec563103b4d4702f3ba7d4d2698e22c158/layer [PUT]

And root cause is the lru_set wrapper did not expect put_content to have additional params and since stream_write calls put_content with 3 arguments, the key position shifts and hence the error. I have refactored the methods appropriately and putting back get_content and put_content to the original signatures.