Using cache and changes with Gitlab CI

I have a project with several independent subdirectories that all contain a built HTML page, as well as a master page.

pages:
    stage: deploy
    tags:
        - shell
    script:
        - mkdir -p public/
        - if [ -d artifacts ]; then cp -r artifacts/* public/; fi
    cache:
        paths:
            - public
    artifacts:
        paths:
        - public
    only: # Only executed for this branch
        - master

mdstyle:
    stage: build
    tags:
        - shell
    script:
        - mkdir -p artifacts/MD-Style/templates
        - cd MD-Style; tar -zcvf ../artifacts/mdstyle.tar.gz *; cd ..
        - cp MD-Style/templates/*.css ./artifacts/MD-Style/templates; cd ..
    artifacts:
        paths:
            - artifacts/mdstyle.tar.gz
            - artifacts/MD-Style
    rules: 
        - if: $CI_COMMIT_BRANCH == "master"
          changes: 
            - MD-Style/**/*

intro-python:
    stage: build
    image: ....
    tags: 
        - docker
    script:
        - mkdir -p artifacts/TPs/Intro-Python
        # Get the style and build
        - cd Intro-Python; cp ../MD-Style/* . -rf; make clean all; cd ..
        # Copy the built files
        - cp -r Intro-Python/build/*  ./artifacts/TPs/Intro-Python/
    artifacts:
        paths:
            - artifacts/TPs/Intro-Python
    rules: 
        - if: $CI_COMMIT_BRANCH == "master"
          changes: 
            - Intro-Python/**/*
            - MD-Style/**/*

I defined these rules hoping that only the subdirectories for which there has been changes in a commit will be recompiled.

The "only rebuild was is required" works but, unfortunately, sometimes I also loose the other subpages that were also built as if the cache: paths: public was not always working. Sometimes it does and sometimes it doesn't. When it doesn't, I only get the subpage that has modified by a commit and the rest is suppressed.

I'm suspecting a lifetime for the cache but I'm not sure. Do you have any idea on the issue or on the possibility to track this issue ? I'm on Gitlab Community Edition 13.3.0.