Git Product home page Git Product logo

fastly-test-blog's Introduction

Fastly Test Blog

This is a blog style application with fake content that can be cached and purged using Fastly. See the related blog post for an overview.

Installation

You will set up a new service in your Fastly account, and configure it in order to familiarize yourself with your account. If you do not have a Fastly account, you will need to create one: https://www.fastly.com/signup

Deploy

Configuration

The initializer, fastly.rb, has the configurations for Fastly.

c.api_key = ENV['FASTLY_API_KEY'] # Fastly api key, required
c.max_age = 86400 # time in seconds, optional, currently set to 1 day
c.service_id = ENV['FASTLY_SERVICE_ID'] # The Fastly service you will be using, required
c.purging_enabled = false unless ENV['ENABLE_PURGE']

Please refer to our documentation to find your Fastly API Key and Fastly Service ID.

You can override c.purging_enabled with ENABLE_PURGE environment variable: export ENABLE PURGE=1

As is, ENABLE_PURGE=1 bundle exec rake test will fail unless the API Key and Service ID are set. Whereas, bundle exec rake test will pass, because purging is disabled.

Using this application with your Fastly account

Setting up your Fastly Service

Within your Fastly account, create a new Service. For this you'll need:

  • Name - type the name of the first service you'd like to create
  • Origin Server Name - type the IP address (or hostname) and port number (usually 80) for your website's server. e.g., https:\\<HEROKU_URL>
  • Domain Name - type the domain name of your website. e.g., <HEROKU_URL>

Finding the Fastly Headers

If your request is being served by Fastly, you will see the following three headers. You will also use these header to determine if your content is cached or not.

  • X-Served-By
  • X-Cache
  • X-Cache-Hits

You can use curl -svo /dev/null <FASTLY_TEST_URL> to see the Fastly Headers. You can also find the request headers for any request in your browser's web inspector or developer tools.

Changing the TTL of content

You can change the TTL, or how long the content is cached, by creating a new Cache Setting using the Fastly Configuration Control Panel.

For example, if you wanted to change the TTL for all /articles pages, you would create the following Cache Setting.

  • Name - Article pages 2 mins
  • TTL - 120 (seconds)
  • Stale TTL - 0 (seconds)
  • Action - Deliver

Then create a condition to match the content.

  • Name - Article pages
  • Apply if - req.url ~ "^/articles/"
  • Priority - 10 (default)

Then activate the version with these changes. If you have previously requested content that matches your new setting, you will need to purge it. You can purge by URL, Surrogate Key, or Purge All.

Passing content

If you do not want specific content to cache, you can create a Cache Setting to Pass on the content instead. You will use the same process for changing the TTL with a few adjustments.

  • Name - Pass About page
  • TTL - 0 (seconds)
  • Stale TTL - 0 (seconds)
  • Action - Pass

Then create a condition to match the content.

  • Name - About page
  • Apply if - req.url ~ "^/about"
  • Priority - 5

License

MIT license, see LICENSE.md

fastly-test-blog's People

Contributors

kamzilla avatar chicagoing avatar aspires avatar mattcone avatar squeemishly avatar blithe avatar akappen avatar

Stargazers

Scott Ellison II avatar  avatar Anna Rajendran avatar Phil avatar Ichi avatar Edilene avatar Michael May avatar Amy Lam avatar Ines Sombra avatar

Watchers

Tyler McMullen avatar Javier Linares avatar Steve Calderon avatar Zac Duncan avatar Josh Lavin avatar Window Snyder avatar Mandy avatar João Taveira Araújo avatar Michael May avatar Luis Flores avatar  avatar Hassan Shahid avatar  avatar  avatar James Cloos avatar gangsterHOTLINE avatar Arpit Desai avatar  avatar Karl J. Smith avatar Doug Chuchro avatar Justin Francesconi avatar  avatar Gu avatar  avatar Lee Chen avatar Emily Shea avatar Chris Gonyea avatar Angel Chin avatar ryan avatar Bhaskar Jayaraman avatar  avatar Chris Buckley avatar Lewis Mbae avatar Jon Pinto avatar Randy Schultz avatar Jeffrey Generao avatar Schuyler Van Horn avatar  avatar Markus Eskola avatar  avatar  avatar Saima Hashimi avatar Caslyn Tonelli avatar Grant Zhang avatar  avatar  avatar  avatar  avatar Jason E avatar  avatar  avatar Fernando Bitti Loureiro avatar Denise McCoy avatar dwayne Johnson avatar Ben Pepper avatar Daniel McCarney avatar  avatar Kay Chung avatar Steven Chuob avatar Satoshi Ishii avatar Paul Scanlon avatar Shohei Maeda avatar Richard Alpagot avatar Julien Maingard avatar  avatar Mandy avatar Vadim Getmanshchuk avatar  avatar oba_wan avatar  avatar  avatar  avatar Rex Osafo-Asare avatar diaonline avatar  avatar  avatar  avatar Sanchita Chamberlain avatar Atsushi Fukuda avatar L Crenshaw avatar  avatar  avatar David A. Bell avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.