N
N
NesteA882020-05-14 15:53:49
PHP
NesteA88, 2020-05-14 15:53:49

How to exclude a piece of php code from caching?

Good afternoon!

The page has a piece of php code that is responsible for rotating blocks when the page is reloaded:

<?php
switch(rand(1,2)){
    case 1:
        ?>
        Блок 1
        <?php
        break;
    case 2:
        ?>
            Блок 2
        <?php
        break;
}
?>


The page is cached. And, accordingly, the block that got into the cache at the first load, and not in random order, is displayed to everyone. Is it possible to exclude this piece of code from caching? Or what are the options?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question