Publi

Borrar la caché de Magento desde la línea de comandos

Foto: Steve Jurvetson (Flickr CC)

Cuando estás haciendo muchos cambios en una instalación de Magento, debes borrar la caché a menudo. Un caso especial es si utilizas scripts periódicos para actualizar listas de precios o stock, en ese caso debes programar también el borrado de cachés.

Este pequeño script ha sido visto en muchas webs por lo que no me extenderé mucho y mencionaré dos fuentes donde podéis consultarlo (os invito a visitar estas páginas porque amplían la información que veis aquí).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
echo "Start Cleaning all caches at ... " . date("Y-m-d H:i:s") . "\n\n";
ini_set("display_errors", 1);

require '../app/Mage.php';
Mage::app('admin')->setUseSessionInUrl(false);
Mage::getConfig()->init();

$types = Mage::app()->getCacheInstance()->getTypes();

try {
    echo "Cleaning data cache... \n";
    flush();
    foreach ($types as $type => $data) {
        echo "Removing $type ... ";
        echo Mage::app()->getCacheInstance()->clean($data["tags"]) ? "Cache cleared!" : "There is some error!";
        echo "\n";
    }
} catch (exception $e) {
    die("[ERROR:" . $e->getMessage() . "]");
}

Aquí veremos un listado de tipos de caché que estamos utilizando en nuestra instalación y se van limpiando.

Si queremos borrar la caché de JS y CSS bastaría con llamar a (debemos asegurarnos de que el usuario que ejecuta el script (si es distinto al que procesa la web) tiene permisos para escribir en la carpeta de caché:

1
2
3
<?php
    Mage::getModel('core/design_package')->cleanMergedJsCss();
    Mage::dispatchEvent('clean_media_cache_after');

Ya podemos llamar al script desde la línea de comandos, por ejemplo, o programarlo como tarea cron.

Visto en:
Yameveo | Flush every Magento cache from the command line
Magento: Clear all caches from command line

También podría interesarte....

There are 4 comments left Ir a comentario

  1. Pingback: Borrar la caché de Magento desde la línea de comandos | PlanetaLibre /

  2. Watson Emmanuel /
    Usando Google Chrome Google Chrome 114.0.0.0 en Windows Windows NT

    I like your article very much. It contains a lot of useful information and is highly thorough. In addition, I want to introduce you to the incredibly original amusement instrument known as rocket bot royale. I nevertheless expect to see more sharing from you in the future. elastic man

  3. Andrew Mark /
    Usando Google Chrome Google Chrome 114.0.0.0 en Windows Windows NT

    I have read your excellent post. This is a great job. I have enjoyed reading your post first time. I want to say thanks for this post. Thank you…
    Drive Scorpion Jacket

  4. OKBet /
    Usando Google Chrome Google Chrome 114.0.0.0 en Windows Windows NT

    Quality posts is the crucial to invite the visitors to visit the web page, that’s what this web page is providing.
    SBK

Leave a Reply to Andrew Mark Cancle Reply