Protected site visible without login

i use Kirby 2.2.3 and have added a login on the website for one site as described in the Cookbook " Authentication" link. I want to protect one sepcific site from the website (like:, so that only logged in users can see this site. Unfortunately if i go direct to the adress (in this example i can see the site and the redirect to the main page ( does not work. I know that the login works, because the content (one pdf file) can only be donwloaded if the user is logged in.
In the template of the site i want to protect i added <?php if(!$site->user()) go('/') ?> at the first line.

The template /site/templates/test.php looks like this:

<?php if(!$site->user()) go('/') ?>

<?php if(!defined('KIRBY')) exit;

snippet("header"); ?>

<main class="block site-width content-default" role="main" id="intro">
	<?php snippet("intro-logo"); ?>
	<h1><?php echo $page->title()->html() ?></h1>
	<?php echo $page->text()->kirbytext() ?>
	    <?php if($user = $site->user()): ?>
  <a href="<?= url('logout') ?>">Logout</a>
<?php endif ?>
<?php snippet('footer') ?>

I have already ask a question related to this topic: Link

Is there something i am missing? I checked all the code a few times with the cookbook and searched the forum, but i do not find any soultion. If any information is missing, I will complete it.
Thanks for your help and i hope i have clearly desribed my problem.

First thing that comes to mind: Is caching enabled in your config?

if(!defined('KIRBY')) exit;

This if statement is not necessary.

Hello, thanks for the quick response!

i deleted the if statement, thanks.

yes, caching is enabled, in the config it looks like this:

c::set('cache', true);
c::set('cache.driver', 'file');
c::set('cache.ignore', array('sitemap', 'login'));

Thanks for your help!

Looks like the page you are trying to protect is not in the list of ignored pages, only the login page? And you have to clear the cache.

Yes, the page was not in the list of ignored pages.

Thank you very much, now it works!