|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Cache in Vue DataManager | Syncfusion |
| 4 | +description: Learn here all about Cache in Syncfusion Vue Data component of Syncfusion Essential JS 2 and more details. |
| 5 | +platform: ej2-vue |
| 6 | +control: Cache |
| 7 | +documentation: ug |
| 8 | +domainurl: ##DomainURL## |
| 9 | +--- |
| 10 | + |
| 11 | +# Enable Cache in Vue Data component |
| 12 | + |
| 13 | +The Syncfusion<sup style="font-size:70%">®</sup> DataManager provides the `enableCache` property, which enhances performance by reducing redundant HTTP requests for previously visited pages. When caching is enabled, the [DataManager](https://ej2.syncfusion.com/documentation/api/data/dataManager/) retrieves data from the cache instead of sending a new request, minimizing server load and improving user experience. |
| 14 | + |
| 15 | +**How it works** |
| 16 | + |
| 17 | +* When `enableCache` is set to true, the DataManager generates a unique ID at initialization and uses it to store previously loaded page data in cache memory. This enables efficient data retrieval without redundant server requests. |
| 18 | +* The cache is automatically cleared when data actions such as sorting, filtering, grouping, searching, or CRUD operations (Create, Read, Update, Delete) are performed. |
| 19 | +* This feature is supported by all adaptors in Syncfusion<sup style="font-size:70%">®</sup> DataManager, ensuring consistent caching behavior across different data sources. |
| 20 | + |
| 21 | +The following example demonstrates how to enable caching using the `enableCache` property in the Syncfusion<sup style="font-size:70%">®</sup> Vue DataManager: |
| 22 | + |
| 23 | +{% tabs %} |
| 24 | +{% highlight html tabtitle="Composition API (~/src/App.vue)" %} |
| 25 | +{% raw %} |
| 26 | + |
| 27 | +<template> |
| 28 | + <div id="app"> |
| 29 | + <ejs-grid :dataSource="data"> |
| 30 | + <e-columns> |
| 31 | + <e-column field='OrderID' headerText='Order ID' width='100' textAlign='Right'></e-column> |
| 32 | + <e-column field='CustomerID' headerText='Customer ID' width='100'></e-column> |
| 33 | + <e-column field='EmployeeID' headerText='Employee ID' width='100' textAlign='Right'></e-column> |
| 34 | + <e-column field="OrderDate" headerText="Order Date" format="yMd" textAlign="Right" width="120"></e-column> |
| 35 | + </e-columns> |
| 36 | + </ejs-grid> |
| 37 | + </div> |
| 38 | +</template> |
| 39 | +<script setup> |
| 40 | +import { DataManager, WebApiAdaptor } from '@syncfusion/ej2-data'; |
| 41 | +import { GridComponent as EjsGrid, ColumnsDirective as EColumns, ColumnDirective as EColumn } from '@syncfusion/ej2-vue-grids'; |
| 42 | + |
| 43 | +const data = new DataManager({ |
| 44 | + url: "https://services.syncfusion.com/vue/production/api/Orders", |
| 45 | + adaptor: new WebApiAdaptor(), |
| 46 | + crossDomain: true, |
| 47 | + enableCache: true // Enables caching to prevent repeated HTTP requests. |
| 48 | +}); |
| 49 | +</script> |
| 50 | +<style> |
| 51 | +@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css"; |
| 52 | +@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css"; |
| 53 | +@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css"; |
| 54 | +@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css"; |
| 55 | +@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css"; |
| 56 | +@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css"; |
| 57 | +@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css"; |
| 58 | +@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css"; |
| 59 | +@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css"; |
| 60 | +</style> |
| 61 | + |
| 62 | +{% endraw %} |
| 63 | +{% endhighlight %} |
| 64 | +{% highlight html tabtitle="Options API (~/src/App.vue)" %} |
| 65 | +{% raw %} |
| 66 | + |
| 67 | +<template> |
| 68 | + <div id="app"> |
| 69 | + <ejs-grid :dataSource="data"> |
| 70 | + <e-columns> |
| 71 | + <e-column field='OrderID' headerText='Order ID' width='100' textAlign='Right'></e-column> |
| 72 | + <e-column field='CustomerID' headerText='Customer ID' width='100'></e-column> |
| 73 | + <e-column field='EmployeeID' headerText='Employee ID' width='100' textAlign='Right'></e-column> |
| 74 | + <e-column field="OrderDate" headerText="Order Date" format="yMd" textAlign="Right" width="120"></e-column> |
| 75 | + </e-columns> |
| 76 | + </ejs-grid> |
| 77 | + </div> |
| 78 | +</template> |
| 79 | +<script> |
| 80 | +import { GridComponent, ColumnDirective, ColumnsDirective } from "@syncfusion/ej2-vue-grids"; |
| 81 | +import { DataManager, WebApiAdaptor } from "@syncfusion/ej2-data"; |
| 82 | + |
| 83 | +export default { |
| 84 | + components: { |
| 85 | + 'ejs-grid': GridComponent, |
| 86 | + 'e-column': ColumnDirective, |
| 87 | + 'e-columns': ColumnsDirective |
| 88 | + }, |
| 89 | + data: () => { |
| 90 | + return { |
| 91 | + data: new DataManager({ |
| 92 | + url: "https://services.syncfusion.com/vue/production/api/Orders", |
| 93 | + adaptor: new WebApiAdaptor(), |
| 94 | + crossDomain: true, |
| 95 | + enableCache: true // Enables caching to prevent repeated HTTP requests. |
| 96 | + }) |
| 97 | + }; |
| 98 | + } |
| 99 | +} |
| 100 | +</script> |
| 101 | +<style> |
| 102 | +@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css"; |
| 103 | +@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css"; |
| 104 | +@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css"; |
| 105 | +@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css"; |
| 106 | +@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css"; |
| 107 | +@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css"; |
| 108 | +@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css"; |
| 109 | +@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css"; |
| 110 | +@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css"; |
| 111 | +</style> |
| 112 | + |
| 113 | +{% endraw %} |
| 114 | +{% endhighlight %} |
| 115 | +{% endtabs %} |
0 commit comments