11import lscache from "lscache" ;
22
3- lscache . setBucket ( "icons" ) ;
3+ const cacheName = "icon:" ;
4+
5+ function setCache ( name , value ) {
6+ lscache . setBucket ( cacheName ) ;
7+ // Store for 1 week 60 min * 24 hours * 7 days = 10080
8+ lscache . set ( name , value , 10080 ) ;
9+ lscache . resetBucket ( ) ;
10+ }
11+
12+ function getCache ( name ) {
13+ lscache . setBucket ( cacheName ) ;
14+ const value = lscache . get ( name ) ;
15+ lscache . resetBucket ( ) ;
16+ return value ;
17+ }
418
519function replaceTag ( element , markup ) {
620 const attributes = [ ...element . attributes ]
@@ -18,7 +32,7 @@ function replaceTag(element, markup) {
1832window . addEventListener ( "alpine:init" , ( ) => {
1933 window . Alpine . data ( "icon" , ( segment ) => ( {
2034 init ( ) {
21- const cache = lscache . get ( segment ) ;
35+ const cache = getCache ( segment ) ;
2236 if ( cache && typeof cache === "string" ) {
2337 replaceTag ( this . $el , cache ) ;
2438 return ;
@@ -31,8 +45,7 @@ window.addEventListener("alpine:init", () => {
3145 return response . text ( ) ;
3246 } )
3347 . then ( ( data ) => {
34- // Store for 1 week 60 min * 24 hours * 7 days = 10080
35- lscache . set ( segment , data , 10080 ) ;
48+ setCache ( segment , data ) ;
3649 replaceTag ( this . $el , data ) ;
3750 } )
3851 . catch ( ( error ) => {
0 commit comments