Skip to content

Instantly share code, notes, and snippets.

@dvershinin

dvershinin/check-cache.sh

Last active Oct 29, 2019
Embed
What would you like to do?
Check for disappearing cache
#!/bin/bash
# Run e.g. check-cache.sh https://www.manzara.si/jakne
# Or time ./check-cache.sh https://www.manzara.si/jakne
if [ $# -eq 0 ]
then
echo "Error: Please specify request URL as argument."
exit 1
fi
TEST_URL="$1"
# run initial warmup
curl -s -L -D /dev/stdout -o initial.html "${TEST_URL}"
# next request should be Hit
X_CACHE="None"
counter=0
until [ "${X_CACHE}" = "MISS" ]
do
((counter++))
echo "Request #${counter}..."
X_CACHE=$(curl -s -L -D /dev/stdout -o current.html "${TEST_URL}" | grep --ignore-case --only-matching --perl-regexp "X-Cache: \K\w+")
echo "Received Cache Status: ${X_CACHE}"
sleep 1
done
echo "Got MISS! Bail! Investigate initial.html vs current.html"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment