-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support for @vue-storefront/cache module (#482)
* chore(theme): added nuxt-image * feat(theme): added nuxt-img to category page * feat: added nuxt-img to category pages, added newe configs, and useImage compoosable * feat(theme): added nuxt-img to products carousel, added image enums * feat(theme): added nuxt-img for search results * feat(theme): added nuxt-img to my account wishlist * feat(theme): changed log to use nuxt-img * feat(theme): changed empty cart icon to use nuxt-img * feat(theme): added nuxt-img to instagram feed, updated image names * feat(theme): changed error image on search results to use nuxt-img * feat(theme): update store switcher to use nuxt-img instead of SfImage * feat(theme): added nuxt-img to wishlist sidebar * feat(theme): added nuxt-img to MobileStoreBanner * feat(theme): added nuxt-img to grouoped product selector * feat(theme): added nuxt-img to payment component * docs: added docs for external images providers * build(cloud): updated vuestorefront cloud docker file and added new args * build: updated deploy gh action to add image env vatiables * docs(configuration): updated docs for image providers * build: added missed buildargs * build: fixed dockerfile * build: fixed typo in docker file * build: updated config * test: add unit tests for the useImage composable * chore(theme): added @vue-storefront-cache module * chore(theme): added config for @vue-storefront/cache to nuxt.config.js * feat(theme): added cache tags to home and category page * chore(theme): added redis-cache module, fixed cache tags for category page * feat(theme): added cache tags to product page, added body parser server middleware * build: added config for redis, modified deployment config for tests * build: removed unnecessary redis_password env variable * build: fixed redis env variables names * feat(theme): added cache tags for cms pages * chore(theme): removed console.logs, added comments to nuxt.config.js * build: removed redis-cache module from package.json and addet it to dockerfile * build: updated dockerfile * build(updzted docker file): updated dovkerfile * build: added REDIS__ENABLED env variable * docs: added docs for redis caching * build: reverted test changes in deploy action * fix(theme): removed typo from Category template n * build: fixed GH deploy action
- Loading branch information
Showing
14 changed files
with
20,633 additions
and
26,967 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,13 @@ ARG STORE_URL | |
ARG MAGENTO_BASE_URL | ||
ARG IMAGE_PROVIDER | ||
ARG IMAGE_PROVIDER_BASE_URL | ||
ARG REDIS__HOST | ||
ARG REDIS__PORT | ||
ARG REDIS__CACHE_INVALIDATE_KEY | ||
ARG REDIS__CACHE_INVALIDATE_URL | ||
ARG REDIS__CACHE_INVALIDATE_URL | ||
ARG REDIS__KEY_PREFIX | ||
ARG REDIS__ENABLED | ||
ARG SENTRY_DSN | ||
|
||
ENV MAGENTO_GRAPHQL=${MAGENTO_GRAPHQL} | ||
|
@@ -27,6 +34,13 @@ ENV NUXT_APP_PORT=3000 | |
ENV MAGENTO_BASE_URL=https://magento2-instance.vuestorefront.io/ | ||
ENV IMAGE_PROVIDER=${IMAGE_PROVIDER} | ||
ENV IMAGE_PROVIDER_BASE_URL=${IMAGE_PROVIDER_BASE_URL} | ||
ENV REDIS__HOST=${REDIS__HOST} | ||
ENV REDIS__PORT=${REDIS__PORT} | ||
ENV REDIS__CACHE_INVALIDATE_KEY=${REDIS__CACHE_INVALIDATE_KEY} | ||
ENV REDIS__CACHE_INVALIDATE_URL=${REDIS__CACHE_INVALIDATE_URL} | ||
ENV REDIS__CACHE_INVALIDATE_URL=${REDIS__CACHE_INVALIDATE_URL} | ||
ENV REDIS__KEY_PREFIX=${REDIS__KEY_PREFIX} | ||
ENV REDIS__ENABLED=${REDIS__ENABLED} | ||
ENV SENTRY_DSN=${SENTRY_DSN} | ||
|
||
|
||
|
@@ -37,7 +51,11 @@ WORKDIR /var/www | |
|
||
COPY . . | ||
|
||
RUN yarn install && yarn build && yarn cache clean --all | ||
RUN yarn install | ||
|
||
RUN npx [email protected] workspace @vue-storefront/magento-theme add @vsf-enterprise/redis-cache | ||
|
||
RUN yarn build && yarn cache clean --all | ||
|
||
COPY .vuestorefrontcloud/docker/vue-storefront.sh /usr/local/bin/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Server-Side Rendering Cache | ||
|
||
## Introduction | ||
|
||
VueStorefront 2 - Magento 2 integrations use @vue-storefront/cache module that adds posibility to cache some server-side | ||
rendered pages. | ||
|
||
### What is cached | ||
The cached pages are: | ||
|
||
* Home page with the `Vhome` tag. | ||
* All CMS pages with the `V${page.identifier}` tag | ||
* Category page with the `Vcategory` tag and tags for products: `P${product.uid}` as well as categories `C${category.slug}` | ||
* Product page with the `Vproduct-${route.value.params.id}` tag and tags for the main product `P${product.uid}` as well as categories `C${cat.id}` | ||
|
||
## Invalidating tags | ||
|
||
To invalidate a tag and remove pages associated with that tag, use the [Invalidation endpoint](https://docs.vuestorefront.io/v2/performance/ssr-cache.html#invalidating-tags). | ||
|
||
Go to the route configured in the `.env` file under the `REDIS__CACHE_INVALIDATE_KEY` key with two query parameters: | ||
* `key` — string matching the `REDIS__CACHE_INVALIDATE_KEY` key in the `.env` file. | ||
* `tags` — a comma-separated list of tags for invalidation. | ||
|
||
Assuming that you are running the application locally, the `REDIS__CACHE_INVALIDATE_URL` key is equal to `/cache-invalidate,` and the `REDIS__CACHE_INVALIDATE_KEY` key is equal to `secret_key`, and you want to invalidate the `Vhome` tag, the full URL will look like this: | ||
|
||
## How to cache other pages | ||
|
||
We added caching only to the most visited pages. However, you can cache other pages as well, including custom ones. You can find detailed instructions on how to use cache on the [SSR Cache](https://docs.vuestorefront.io/v2/performance/ssr-cache.html) and [Redis cache](https://docs.vuestorefront.io/v2/integrations/redis-cache.html) pages. | ||
|
||
:::tip | ||
You don't need to add any additional packages to cache more pages — just add or modify tags in components. | ||
::: | ||
|
||
## Cache drivers | ||
|
||
@vue-storefront/cache module is open source and provided Out Of The Box by Magento 2 integration. | ||
To set up caching in your store, you must install and configure a cache driver. | ||
You can use our enterprise `@vsf-enterprise/redis-cache` module, or build your cache driver. | ||
|
||
### Redis cache (enterprise) | ||
Once you have access to the [Vue Storefront npm registry](https://docs.vuestorefront.io/v2/general/enterprise.htm), | ||
you can install the Redis cache driver by running this command in a console: | ||
|
||
``yarn add @vsf-enterprise/redis-cache`` | ||
|
||
|
||
#### redis cache configuration | ||
|
||
Once you have the Redis driver installed, you need to add the Redis configuration to your project's `.env` file. | ||
|
||
``` | ||
.env | ||
REDIS__HOST=127.0.0.1 | ||
REDIS__PORT=6379 | ||
REDIS_PASSWORD= | ||
REDIS__KEY_PREFIX= | ||
REDIS__CACHE_INVALIDATE_URL=/cache-invalidate | ||
REDIS__ENABLED=false | ||
``` | ||
|
||
Then you have to update `nuxt.config.js file` and add this to the `modules` object: | ||
|
||
```javascript | ||
['@vue-storefront/cache/nuxt', { | ||
enabled: process.env.REDIS__ENABLED, | ||
invalidation: { | ||
endpoint: process.env.REDIS__CACHE_INVALIDATE_URL, | ||
key: process.env.REDIS__CACHE_INVALIDATE_KEY, | ||
handlers: [ | ||
'@vue-storefront/cache/defaultHandler', | ||
], | ||
}, | ||
driver: [ | ||
'@vsf-enterprise/redis-cache', | ||
{ | ||
// docs: https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options | ||
redis: { | ||
keyPrefix: process.env.REDIS__KEY_PREFIX, | ||
host: process.env.REDIS__HOST, | ||
port: process.env.REDIS__PORT, | ||
}, | ||
}, | ||
], | ||
}], | ||
``` | ||
|
||
## Useful links | ||
|
||
- https://docs.vuestorefront.io/v2/performance/ssr-cache.html | ||
- https://docs.vuestorefront.io/v2/integrations/redis-cache.html | ||
- https://docs.vuestorefront.io/v2/integrate/cache-driver.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const bodyParser = require('body-parser'); | ||
const app = require('express')(); | ||
|
||
app.use(bodyParser.json()); | ||
module.exports = app; |
Oops, something went wrong.