Cache Concept

The Cache concept uses the Cache Service Worker API. It lets you add your endpoints (or others) to the cache, and automatically caches media you upload with the Loader concept.

He doesn't manage your headers.

How it works

  • For activate the cache, go to your admin (yourdomain.com/admin/wp-admin/admin.php?page=site-settings) and click on Extra tab, you'll see Cache version and Cache Expiration. Version 0 will disable your cache, just add a version.

  • When you change the version, the previous cache is deleted.

  • Add in cache: For example, put a look on what we have do for get pages before we have server-side injecting:

    try{
    
        const pagesPromise = fetch(await Cache.get(SYSTEM.restPath + 'wp/v2/pages?_fields=id,title,link,acf'));
    
    
        const [callPages] = await Promise.all([pagesPromise]);
    
        if(!callPages.ok) throw new Error('Pages can\'t be loaded');
    
    
        Cache.put(callPages.url, callPages.clone());
    
    
        const pages = await callPages.json();
    
    }
  • Cache Concept works only on secure URLs.

  • It's ok to have Cache.get() even if cache don't work. It'll return the first parameter.

  • It's ok to have Cache.put() even if you don't need to do it, because the function will work only if the url is not on protocol blob: and if cache work.

  • You can use WordPress Hook like save_post with update_field of ACF for update your Cache version when a post is saved

Last updated