Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #1641 - output caching with dynamic tags #1731

Merged
merged 2 commits into from
Sep 14, 2018
Merged

Feature #1641 - output caching with dynamic tags #1731

merged 2 commits into from
Sep 14, 2018

Conversation

pkarw
Copy link
Collaborator

@pkarw pkarw commented Sep 14, 2018

SSR Cache

Vue Storefront generates the Server Side rendered pages to improve the SEO results. In the latest version of Vue Storefront we've added the Output cache option (disabled by default) to improve the performance.

The output cache is set by the following config/local.json variables:

    "server": {
      "host": "localhost",
      "port": 3000,
      "protocol": "http",
      "api": "api",
      "useOutputCacheTagging": true,
      "useOutputCache": true,
      "outputCacheDefaultTtl": 86400
    },
    "redis": {
      "host": "localhost",
      "port": 6379,
      "db": 0
    },  

Dynamic tags

The dynamic tags config uption: useOutputCacheTaging - if set to true, Vue Storefront is generating the special HTTP Header X-VS-Cache-Tags

        res.setHeader('X-VS-Cache-Tags', cacheTags)

Cache tags are assigned regarding the products and categories which are used on the specific page. Typical X-VS-Cache-Tags tag looks like this:

X-VS-Cache-Tags: P1852 P198 C20

The tags can be used to invalidate the Varnish cache if You're using it. Read more on that.

Redis

If both useOutputCache and useOutputCacheTagging options are set to true - Vue Storefront is using Output Cache stored in Redis (configured in the redis section of the config file). Cache is tagged with Dynamic tags and can be invalidated using special webhook:

Example call to clear all pages containing specific product and category:
curl http://localhost:3000/invalidate?tag=P1852,C20

Example call to clear all product, category and home pages:
curl http://localhost:3000/invalidate?tag=product,category,home

WARNING:
We strongly recommend You to NOT USE Output cache in the development mode. By using it You won't be able to refresh the UI changes after modyfing the Vue components etc.

Cache invalidation: Recent version of mage2vuestorefront do support output cache invalidation. Output cache is being tagged with the product and categories id (products and categories used on specific page). Mage2vuestorefront can invalidate cache of product and category pages if You set the following ENV variables:

export VS_INVALIDATE_CACHE_URL=http://localhost:3000/invalidate?tag=
export VS_INVALIDATE_CACHE=1

Contribution and currently important rules acceptance

To test it please modify the config/local.json:
```json
server: {
      "useOutputCacheTagging": true,
      "useOutputCache": true,
      "outputCacheDefaultTtl": 86400
    },
```

+ set the `reds` section (default is set to Your localhost)
@pkarw pkarw changed the base branch from master to develop September 14, 2018 13:30
@pkarw pkarw merged commit f8461be into vuestorefront:develop Sep 14, 2018
@pkarw pkarw mentioned this pull request Aug 15, 2019
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant