Opencart 3.0.3.1 + Journal 3.0.46 no cache for manufacturer pages

AndreyPopov

Well-Known Member
#42
I use a normal browser. I see cookies that are set, but no _lscache_vary cookies
by default _lscache_vary sets for:
- languages, if store is multilanguage
- currencies, if store is multicurrency
- private/ESI, if enabled Separate View for logged user or ESI enabled
- for Safari browser ( _lscache_vary=browser:safari; )
- for Mobile device UA ( _lscache_vary=device:mobile|tablet; )

if store use:
- only one language
- only one currency
- not private/ESI
- not Apple
- not Phone|Tablet

_lscache_vary not sets
 

serpent_driver

Well-Known Member
#45
Yes, for Multithreading Magic Crawler. :) I don't really need these cookies, but they make it easier to define safe cache rules. The current are not really good.
 

AndreyPopov

Well-Known Member
#46
for crawler I add some code "for me" and my Advanced Crawler ;)

PHP:
    protected function CookiesForCrawler($userAgent,$cookie,$is_lscache) {

     if ( $is_lscache == TRUE ) {
        $cookie = str_replace('_lscache_vary=','',$cookie);
        if ( stripos($cookie, 'session') == FALSE ) {$cookie_sess = '';}
        if ( stripos($cookie, 'language') == FALSE ) {$cookie_lang = '';}
        if ( stripos($cookie, 'currency') == FALSE ) {$cookie_curr = '';}
        $cookies_lscache =  explode( ',', $cookie );
        foreach ( $cookies_lscache as $cookie_lscache ) {
                    if ( stripos($cookie_lscache, 'session') !== FALSE ) {$cookie_sess = $cookie_lscache;}
        if ( stripos($cookie_lscache, 'language') !== FALSE ) {$cookie_lang = $cookie_lscache;}
        if ( stripos($cookie_lscache, 'currency') !== FALSE ) {$cookie_curr = $cookie_lscache;}
        }
        $cookie = '';
     } else {
             $cookie_sess = '';
            $cookie_lang = '';
            $cookie_curr = '';
     }

        $cookie_ua = '';
        $cookie_uap = '';
        $cookie_uab = '';
        $cookie_uas = '';
        if ( (stripos($userAgent, 'bot') !== FALSE) || (stripos($userAgent, 'compatible') !== FALSE) ) {
            $cookie_ua = '';
            $cookie_uap = '';
            $cookie_uab = '';
            $cookie_uas = '';
            $cookie_sess = '';
            $cookie_lang = '';
            $cookie_curr = '';
        } else {
            if ( (stripos($userAgent, 'OPR') !== FALSE) || (stripos($userAgent, 'OPT') !== FALSE) || (stripos($userAgent, 'Opera') !== FALSE) ) {
                //$cookie_uab = 'browser%3Aopera';
                $cookie_uab = 'browser%3Achrome';
            } elseif ( (stripos($userAgent, 'FxiOS') !== FALSE) || (stripos($userAgent, 'Firefox') !== FALSE) ) {
                //$cookie_uab = 'browser%3Afirefox';
                $cookie_uab = 'browser%3Achrome';
            } elseif ( (stripos($userAgent, 'Edg') !== FALSE) ) {
                //$cookie_uab = 'browser%3Aedge';
                $cookie_uab = 'browser%3Achrome';
            } elseif ( (stripos($userAgent, 'YaBrowser') !== FALSE) ) {
                //$cookie_uab = 'browser%3Ayandex';
                $cookie_uab = 'browser%3Achrome';
            } elseif ( (stripos($userAgent, 'Lighthouse') !== FALSE) || (stripos($userAgent, 'Headless') !== FALSE) ) {
                $cookie_uab = 'browser%3Alighthouse';
            } elseif ( (stripos($userAgent, 'CriOS') !== FALSE) || (stripos($userAgent, 'Chrome') !== FALSE) ) {
                $cookie_uab = 'browser%3Achrome';
            } elseif ( (stripos($userAgent, 'Safari') !== FALSE) ) {
                $cookie_uab = 'browser%3Asafari';
            } elseif ( (stripos($userAgent, 'Instagram') !== FALSE) ) {
                //$cookie_uab = 'browser%3Ainstagram';
                $cookie_uab = 'browser%3Achrome';
            } else {
                $cookie_uab = 'browser%3Aunknown';
            }

            if (stripos($userAgent, 'Macintosh') !== FALSE) {
                $cookie_uap = 'apple%3Amacintosh';
            } elseif (stripos($userAgent, 'iPhone') !== FALSE) {
                $cookie_uap = 'apple%3Aiphone';
            } elseif (stripos($userAgent, 'iPad') !== FALSE) {
                $cookie_uap = 'apple%3Aipad';
            } else {
                $cookie_uap = '';
            }

            if (stripos($userAgent, 'Windows') !== FALSE) {
                $cookie_uas = 'os%3Awindows';
            } elseif (stripos($userAgent, 'Linux') !== FALSE) {
                $cookie_uas = 'os%3Alinux';
            } else {
                $cookie_uas = '';
            }

            if (stripos($userAgent, 'iPhone') !== FALSE){
                $cookie_ua = 'device%3Amobile';
            } elseif (stripos($userAgent, 'iPad') !== FALSE){
                $cookie_ua = 'device%3Atablet';
            } elseif ( (stripos($userAgent, 'Android') !== FALSE) && (stripos($userAgent, 'Chrome') !== FALSE) && (stripos($userAgent, 'Mobile') !== FALSE) ){
                $cookie_ua = 'device%3Amobile';
            } elseif ( (stripos($userAgent, 'Android') !== FALSE) && (stripos($userAgent, 'Chrome') !== FALSE) && (stripos($userAgent, 'Mobile') == FALSE) ){
                $cookie_ua = 'device%3Atablet';
            } else {
                $cookie_ua = '';
            }

        }

        //apple cookie
        if ( !( $cookie_uap == '') ) {
            if (strpos($cookie, '_lscache_vary') !== FALSE){
                //$cookie .= ',';
                $cookie .= '%2C';
                $cookie .= $cookie_uap;
            } else {
                $cookie = '_lscache_vary=' . $cookie_uap;
            }
        }

        //browser cookie
        if ( !( $cookie_uab == '') ) {
            if (strpos($cookie, '_lscache_vary') !== FALSE){
                //$cookie .= ',';
                $cookie .= '%2C';
                $cookie .= $cookie_uab;
            } else {
                $cookie = '_lscache_vary=' . $cookie_uab;
            }
        }

        //currency cookie
        if ( !( $cookie_curr == '') ) {
            if (strpos($cookie, '_lscache_vary') !== FALSE){
                //$cookie .= ',';
                $cookie .= '%2C';
                $cookie .= $cookie_curr;
            } else {
                $cookie = '_lscache_vary=' . $cookie_curr;
            }
        }

        //device cookie
        if ( !( $cookie_ua == '') ) {
            if (strpos($cookie, '_lscache_vary') !== FALSE){
                //$cookie .= ',';
                $cookie .= '%2C';
                $cookie .= $cookie_ua;
            } else {
                $cookie = '_lscache_vary=' . $cookie_ua;
            }
        }

        //language cookie
        if ( !( $cookie_lang == '') ) {
            if (strpos($cookie, '_lscache_vary') !== FALSE){
                //$cookie .= ',';
                $cookie .= '%2C';
                $cookie .= $cookie_lang;
            } else {
                $cookie = '_lscache_vary=' . $cookie_lang;
            }
        }

        //os cookie
        if ( !( $cookie_uas == '') ) {
            if (strpos($cookie, '_lscache_vary') !== FALSE){
                //$cookie .= ',';
                $cookie .= '%2C';
                $cookie .= $cookie_uas;
            } else {
                $cookie = '_lscache_vary=' . $cookie_uas;
            }
        }

        //session cookie
        if ( !( $cookie_sess == '') ) {
            if (strpos($cookie, '_lscache_vary') !== FALSE){
                //$cookie .= ',';
                $cookie .= '%2C';
                $cookie .= $cookie_sess;
            } else {
                $cookie = '_lscache_vary=' . $cookie_sess;
            }
        }

        return $cookie;

    }
and call
PHP:
$cookie = $this->CookiesForCrawler($userAgent,'',FALSE);
before curl_init


P.S. developers not want implement this because "huge size of cache generated" :(
 
Last edited:

serpent_driver

Well-Known Member
#51
Of course it is matters for both. Unsufficient cache rules causes wrong cached pages. I checked your page today and found some wrongly defined cache rules regarding apple devices.
 
Top