admin-utilities-cache.vue 3.95 KB
Newer Older
1 2 3
<template lang='pug'>
  v-card
    v-toolbar(flat, color='primary', dark, dense)
4
      .subtitle-1 {{ $t('admin:utilities.cacheTitle') }}
5
    v-card-text
6 7 8 9
      .subtitle-1.pb-3.primary--text Flush Pages and Assets Cache
      .body-2 Pages and Assets are cached to disk for better performance. You can flush the cache to force all content to be fetched from the DB again.
      v-btn(outlined, color='primary', @click='flushCache', :disabled='loading').ml-0.mt-3
        v-icon(left) mdi-gesture-double-tap
10
        span Proceed
11 12 13 14 15 16
      v-divider.my-5
      .subtitle-1.pb-3.primary--text Flush Temporary Uploads
      .body-2 New uploads are temporarily saved to disk while they are being processed. They are automatically deleted after processing, but you can force an immediate cleanup using this tool.
      .body-2.red--text Note that performing this action while an upload is in progress can result in a failed upload.
      v-btn(outlined, color='primary', @click='flushUploads', :disabled='loading').ml-0.mt-3
        v-icon(left) mdi-gesture-double-tap
17
        span Proceed
18 19 20 21 22 23
      v-divider.my-5
      .subtitle-1.pb-3.primary--text Flush Client-Side Locale Cache
      .body-2 Locale strings are cached in the browser local storage for 24h. You can delete your current cache in order to fetch the latest data during the next page load.
      .body-2 Note that this affects only #[strong your own browser] and not everyone.
      v-btn(outlined, color='primary', @click='flushClientLocaleCache', :disabled='loading').ml-0.mt-3
        v-icon(left) mdi-gesture-double-tap
24
        span Proceed
25 26 27
</template>

<script>
Nick's avatar
Nick committed
28 29 30 31
import _ from 'lodash'
import utilityCacheFlushCacheMutation from 'gql/admin/utilities/utilities-mutation-cache-flushcache.gql'
import utilityCacheFlushUploadsMutation from 'gql/admin/utilities/utilities-mutation-cache-flushuploads.gql'

32
export default {
Nick's avatar
Nick committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
  data() {
    return {
      loading: false
    }
  },
  methods: {
    async flushCache() {
      this.loading = true
      this.$store.commit(`loadingStart`, 'admin-utilities-cache-flushCache')

      try {
        const respRaw = await this.$apollo.mutate({
          mutation: utilityCacheFlushCacheMutation
        })
        const resp = _.get(respRaw, 'data.pages.flushCache.responseResult', {})
        if (resp.succeeded) {
          this.$store.commit('showNotification', {
            message: 'Cache flushed successfully.',
            style: 'success',
            icon: 'check'
          })
        } else {
          throw new Error(resp.message)
        }
      } catch (err) {
        this.$store.commit('pushGraphError', err)
      }

      this.$store.commit(`loadingStop`, 'admin-utilities-cache-flushCache')
      this.loading = false
    },
    async flushUploads() {
      this.loading = true
      this.$store.commit(`loadingStart`, 'admin-utilities-cache-flushUploads')

      try {
        const respRaw = await this.$apollo.mutate({
          mutation: utilityCacheFlushUploadsMutation
        })
        const resp = _.get(respRaw, 'data.assets.flushTempUploads.responseResult', {})
        if (resp.succeeded) {
          this.$store.commit('showNotification', {
            message: 'Temporary Uploads flushed successfully.',
            style: 'success',
            icon: 'check'
          })
        } else {
          throw new Error(resp.message)
        }
      } catch (err) {
        this.$store.commit('pushGraphError', err)
      }

      this.$store.commit(`loadingStop`, 'admin-utilities-cache-flushUploads')
      this.loading = false
88 89 90 91 92 93 94 95 96 97 98 99 100
    },
    async flushClientLocaleCache () {
      for (let i = 0; i < window.localStorage.length; i++) {
        const lsKey = window.localStorage.key(i)
        if (_.startsWith(lsKey, 'i18next_res')) {
          window.localStorage.removeItem(lsKey)
        }
      }
      this.$store.commit('showNotification', {
        message: 'Locale Client-Side Cache flushed successfully.',
        style: 'success',
        icon: 'check'
      })
Nick's avatar
Nick committed
101 102
    }
  }
103 104 105 106 107 108
}
</script>

<style lang='scss'>

</style>