apicache /

Filename Size Date modified Message
2.0 KB
265 B
167.1 KB
-*- markdown -*-

# Using Squid to develop against API-limited services

The ideal of test driven development is to run all your tests all the time time.  This might be a problem if you are developing against an web service that gives you X requests per hour.

## Getting started

1. Install Squid 2.7, other versions may or may not work.
1. Clone the repository.
1. Open up `squid.conf` and search for `refresh_pattern`.  Change the web service name to the one you want to cache.
1. If your system doesn't have a `/tmp`, search for the path and replace it with an appropriate one.
1. Run ``
1. Point your traffic at proxy port 3128.

## Squid

> Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It runs on most available operating systems, including Windows and is licensed under the GNU GPL.

We can turn the cacheing up a notch to aggressively cache API requests, constantly returning the same data during development without wearing down our API limit.

I'm using squid 2.7.STABLE9 from macports.

### Configuration

The key configurations are:

    refresh_pattern	1440	90%	14400 ignore-no-cache
    #refresh_pattern -i (/cgi-bin/|\?) 0	0%	0

A sample configuration is in `squid.conf`  The configuration file has some baked in paths, so you might want to review.

### Running

`` will start the squid server running on the console.  So far it has only been tested on an OS X machine.

## API Requirements

Not everything is cacheable.  If your API has timestamp parameters to break caching, you will have to turn them off, or search the repository history for `storeurl_rewrite_program` and modify it to your needs.


Changing response content (such as JSONP) is violently uncacheable.  You will either have to turn it off for development, or figure out how to make squid rewrite the response body.