Caching with url authentication

May 7, 2009 at 2:32 AM
Edited May 7, 2009 at 2:34 AM
I'm trying to figure out how to cache my images but also have authentication.  Is there a way in ThreeSharp to do something like this thread talks about?

http://developer.amazonwebservices.com/connect/thread.jspa?messageID=111872

That talks about generating a signature based on time intervals so that the url querystring stays the same for a bit and allows the browser to prevent a GET call to s3...

Thanks,
Mike
May 7, 2009 at 5:04 AM
In case anyone wants to know this is what I did and it is working well.. It removes my s3 get calls saving $, improves performance, and stops effective hotlinking.

I will probably clean it up but this is a start.

I used this function:

private static long GetImageExpireInSeconds()
        {
            int seconds = awsImageCacheSeconds; //from config file
            int graceseconds = 10;
            int expireinterval = (seconds * 1000) + (graceseconds * 1000);
            long timestamp = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds;
            timestamp -= (timestamp % expireinterval);
            timestamp += expireinterval + graceseconds;
            long expiresin = timestamp / 1000;

            return expiresin;
           
        }

I overloaded this in the library:

        public UrlGetResponse UrlGet(UrlGetRequest request)
        {
            return UrlGet(request, -1);
        }

        public UrlGetResponse UrlGet(UrlGetRequest request, long expires)
        {
            UrlGetResponse response = new UrlGetResponse();
           
            if(expires == -1)
                expires = (ThreeSharpUtils.CurrentTimeMillis() + request.ExpiresIn) / 1000;
.....
....