1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.announce.service;
35
36 import fr.paris.lutece.plugins.announce.business.Announce;
37 import fr.paris.lutece.plugins.announce.business.Category;
38 import fr.paris.lutece.portal.service.cache.AbstractCacheableService;
39
40
41
42
43 public final class AnnounceCacheService extends AbstractCacheableService
44 {
45 private static final String CACHE_SERVICE_NAME = "announce.announceCacheService";
46 private static final String ANNOUNCE_KEY_PREFIXE = "announce.announce.";
47 private static final String CATEGORY_KEY_PREFIXE = "announce.category.";
48 private static final String PUBLISHED_ANNOUNCES_ID_LIST_KEY_PREFIXE = "announce.announce.allPublishedId";
49 private static AnnounceCacheServicee/AnnounceCacheService.html#AnnounceCacheService">AnnounceCacheService _instance = new AnnounceCacheService( );
50
51
52
53
54 private AnnounceCacheService( )
55 {
56 initCache( );
57 }
58
59
60
61
62
63
64 public static AnnounceCacheService getService( )
65 {
66 return _instance;
67 }
68
69
70
71
72
73
74
75
76 public static String getAnnounceCacheKey( int nIdAnnounce )
77 {
78 return ANNOUNCE_KEY_PREFIXE + nIdAnnounce;
79 }
80
81
82
83
84
85
86
87
88 public static String getCategoryCacheKey( int nIdCategory )
89 {
90 return CATEGORY_KEY_PREFIXE + nIdCategory;
91 }
92
93
94
95
96
97
98 public static String getListIdPublishedAnnouncesCacheKey( )
99 {
100 return PUBLISHED_ANNOUNCES_ID_LIST_KEY_PREFIXE;
101 }
102
103
104
105
106 @Override
107 public String getName( )
108 {
109 return CACHE_SERVICE_NAME;
110 }
111
112
113
114
115 @Override
116 public Object getFromCache( String strKey )
117 {
118 Object object = super.getFromCache( strKey );
119
120 if ( object != null )
121 {
122 if ( object instanceof Announce )
123 {
124 return ( (Announce) object ).clone( );
125 }
126
127 if ( object instanceof Category )
128 {
129 return ( (Category) object ).clone( );
130 }
131 }
132
133 return object;
134 }
135
136
137
138
139 @Override
140 public void putInCache( String strKey, Object object )
141 {
142 Object clonedObject = object;
143
144 if ( object instanceof Announce )
145 {
146 clonedObject = ( (Announce) object ).clone( );
147 }
148
149 if ( object instanceof Category )
150 {
151 clonedObject = ( (Category) object ).clone( );
152 }
153
154 super.putInCache( strKey, clonedObject );
155 }
156 }