Obviously if there are multiple good answers in here, don't
cache isn't the solution and given that this is the content
of our lecture, we're going to continue with our caching. So, let's
look at these other three. Improve the cache to automatically expire
after some time. I'm not going to count this as correct. Although
it is possible. And actually many caches, and the, the, the
main cache we'll be talking about shortly, has this ability. But
that doesn't solve our problem here, because if things automatically disappear
out of the cache after some amount of time, there's no
guarantee that that's going to coincide with our submission time. So
let's look at the other answer, after submitting, clear the cache.
Yes. This will work. This basically restores the cache to the
state that it was in before we did a request. So
you submit some art. We store it in the database, and
then we blank the cache, and then the next page load
clears the cache. Another answer after submitting, update the cache. This also
works, but it makes things more complicated. So,
in other words, after submitting a piece of art,
we update the database, and we immediately update
the cache at the same time so that the
next page load of the front page has
an updated version of the art. This would work,
but it's, it's more complex, so let's start with
the first solution after we submit clear the cache.
ではそれぞれ見ていきましょう
"キャッシュしない"は解決法にはなりません
むしろ重要な方法です 他の3つはどうでしょう
"キャッシュに有効期限を設けてある段階で更新する"
という選択肢については可能ですが
現実的に正しくないと言えます
有効期限を設けるキャッシュ機能もありますが
今回のケースでは解決法にはなりません
キャッシュが一定の時間で
自動的に消えたら
投稿のタイミングと合致しない可能性があるからです
"投稿後にキャッシュをクリアする"は効果的です
リクエストを出す時点までキャッシュが
残ることになるからです
作品をデータベースに記録して古いキャッシュを削除し
次にページを読み込むと再びクリアします
"投稿のあとにキャッシュを更新する"については
効果がありますが少し複雑です
新しい作品を投稿して
データベースを更新すると同時に
キャッシュをアップデートします
そしてトップページを読み込むと
最新版が見られるという仕組みです
これは少し複雑な作業ですので
"投稿後にキャッシュを消去"を先に説明します