Reference - Cache backends - memcached


App: regression/cache_memcached - Page: delete
PHP
delete.php
HTML
delete.pad
Result
<?php

// A deleted entry takes the URL's entry with it: cache/inits.php answers a client's
// If-None-Match with 304 from the ETag the URL names, so a URL still naming a deleted
// ETag answered 304 for a page that was no longer stored. The backend is asked directly,
// under a key of its own, so the answer does not depend on what the crawl left behind.

$deleteUrl = padMD5 ( 'delete ' . hrtime ( TRUE ) );
$deleteEtag = padMD5 ( 'delete etag ' . hrtime ( TRUE ) );

padCacheStore ( $deleteUrl, $deleteEtag, 'the body' );

$deleteBefore = padCacheUrl ( $deleteUrl );

padCacheDelete ( $deleteUrl, $deleteEtag );

$deleteAfter = padCacheUrl ( $deleteUrl );

$deleteNamed = ( ( $deleteBefore ['etag'] ?? $deleteBefore [1] ?? '' ) === $deleteEtag ) ? 'yes' : 'NO';
$deleteGone = ( ( $deleteAfter ['etag'] ?? $deleteAfter [1] ?? '' ) === '' ) ? 'yes' : 'NO';

?>
<p>stored, the url names its etag: <b>{$deleteNamed}</b></p>
<p>deleted, the url names none: <b>{$deleteGone}</b></p>


App: regression/cache_memcached - Page: index
PHP
index.php
HTML
index.pad
Result
<?php

// Fetches the probe twice. The probe's body embeds its build moment in nanoseconds, so
// two equal bodies mean the second fetch was answered from the memcached cache.

$one = padCurl ( $padHost . 'regression/cache_memcached/?probe&padInclude' );
$two = padCurl ( $padHost . 'regression/cache_memcached/?probe&padInclude' );

$verdict = ( trim ( $one ['data'] ) != '' and $one ['data'] === $two ['data'] ) ? 'yes' : 'NO';

$backend = $padCacheServerType;

?>
<p>backend: {$backend}</p>
<p>two fetches of the probe answer with one body: <b>{$verdict}</b></p>


App: regression/cache_memcached - Page: nodata
PHP
nodata.php
HTML
nodata.pad
Result
<?php

// With $padCacheServerNoData the backend keeps no body, but the URL still has to name the
// ETag stored for it: cache/inits.php finds the ETag it answers a client's If-None-Match
// with 304 for through the URL alone. The backend is asked directly, under a key of its
// own, so the answer does not depend on what the crawl's page fetches left behind.

$noDataKeep = $padCacheServerNoData;
$noDataUrl = padMD5 ( 'nodata ' . hrtime ( TRUE ) );
$noDataEtag = padMD5 ( 'nodata etag ' . hrtime ( TRUE ) );

$padCacheServerNoData = TRUE;

padCacheStore ( $noDataUrl, $noDataEtag, 'the body' );

$noDataRow = padCacheUrl ( $noDataUrl );
$noDataBody = padCacheBody ( $noDataEtag );

padCacheDelete ( $noDataUrl, $noDataEtag );

$padCacheServerNoData = $noDataKeep;

$noDataNamed = ( is_array ( $noDataRow ) and ( $noDataRow ['etag'] ?? $noDataRow [1] ?? '' ) === $noDataEtag ) ? 'yes' : 'NO';
$noDataKept = $noDataBody ? 'yes' : 'no';

?>
<p>without data the url names its etag: <b>{$noDataNamed}</b></p>
<p>a body is kept: {$noDataKept}</p>


App: regression/cache_memcached - Page: probe
PHP
probe.php
HTML
probe.pad
Result
<?php

// A body that is different on every build: nanoseconds. Two fetches answering with the
// same body therefore prove the second came from the cache, not from a build.

$stamp = hrtime ( TRUE );

?>
{# The probe prints a different number on every build - but the cache serves the same body
twice, which defeats the crawl's random-word double-draw check: its two draws agree and
differ from the stored copy. So the crawl marks this page uncomparable by name instead,
in getRegressionGo's list. #
}

{$stamp}