Skip to content

Instantly share code, notes, and snippets.

@posulliv
Created November 10, 2009 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save posulliv/230509 to your computer and use it in GitHub Desktop.
Save posulliv/230509 to your computer and use it in GitHub Desktop.
try
{
/* check memcached first */
if (isMemcachedUsed())
{
getCache()->get(key, ret_val);
if (! ret_val.empty())
{
return true;
}
}
/* ok, we missed in memcache - lets go to S3 */
S3ConnectionPtr s3_ptr= conn_pool->getConnection();
GetResponsePtr get_ptr= s3_ptr->get(bucket_name, key);
istream &in_stream= get_ptr->getInputStream();
uint64_t len= get_ptr->getContentLength();
char *buffer= new char[len];
if (in_stream.good())
{
in_stream.read(buffer, len);
}
ret_val.reserve(len);
ret_val.assign(buffer, buffer + len);
delete [] buffer;
/* now push that value to memcached */
if (isMemcachedUsed())
{
if (! getCache()->set(key, ret_val, 0, 0))
{
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment