Skip to content

静的コンテンツのCDNキャッシュ対応 #26

Open
@hangingman

Description

@hangingman

ref https://fswiki.osdn.jp/cgi-bin/wiki.cgi?page=BugTrack%2Dplugin%2F219

動機

  • freestylewikiをサーバで動作させていると、Perlによるアプリケーション処理が毎回走るので遅い
  • CDN(CloudFlare)でキャッシュさせようとしても、以下のように Cache_Control => 'no-cache' が入っているのでうまくキャッシュできない
    https://github.com/hangingman/fswiki/search?q=no-cache

#------------------------------------------------------------------------------
# 出力処理
#------------------------------------------------------------------------------
my $res = Plack::Response->new(200);
$res->headers(HTTP::Headers->new(
Pragma => 'no-cache',
Cache_Control => 'no-cache',
Content_Type => 'text/html'
));

no-cache — Indicates the response cannot be used to satisfy a subsequent request without successful validation on the origin server. This allows an origin server to prevent a cache from using the origin to satisfy a request without contacting it, even by caches that have been configured to send stale responses.

検討

下記のような仕様を考えた

  • fswikiは通常はリクエストをすべてキャッシュさせる
    • ただし、ページの参照レベルが全員に公開の場合のみ
  • キャッシュ済みのページへのリクエストはcloudflare上のキャッシュを返却する
  • wikiのページが更新されたときにcloudflare上のキャッシュをpurgeする

fswikiの更新契機は、すべてsave_pageが実行されたときなのでhookはそのタイミングで実行される

CloudFlareへのキャッシュ用ヘッダを返す処理と、wikiのページが更新されたときにcloudflare上のキャッシュをpurgeする処理の2つをpluginの中で書くイメージ。

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions