1
2
3
4 package fr.paris.lutece.plugins.dila.utils;
5
6 import fr.paris.lutece.plugins.dila.utils.constants.DilaConstants;
7
8 import org.apache.commons.lang.StringUtils;
9
10
11
12
13
14
15 public final class CacheKeyUtils
16 {
17
18
19
20 private CacheKeyUtils( )
21 {
22 }
23
24
25
26
27
28
29
30 public static String generateCacheKey( Long lCategoryId, String strCardId )
31 {
32 StringBuilder sbKey = new StringBuilder( );
33 sbKey.append( lCategoryId ).append( DilaConstants.CACHE_KEY_SEPARATOR ).append( strCardId );
34
35 return sbKey.toString( );
36 }
37
38
39
40
41
42
43 public static Long getCategoryFromCacheKey( String strKey )
44 {
45 Long catId = null;
46
47 if ( StringUtils.isNotBlank( strKey ) )
48 {
49 String[] splitKey = strKey.split( DilaConstants.CACHE_KEY_SEPARATOR );
50
51 if ( ( splitKey.length >= 1 ) && StringUtils.isNumeric( splitKey[0] ) )
52 {
53 catId = Long.valueOf( splitKey[0] );
54 }
55 }
56
57 return catId;
58 }
59
60
61
62
63
64
65 public static String getCardIdFromCacheKey( String strKey )
66 {
67 String cardId = null;
68
69 if ( StringUtils.isNotBlank( strKey ) )
70 {
71 String[] splitKey = strKey.split( DilaConstants.CACHE_KEY_SEPARATOR );
72
73 if ( splitKey.length == 2 )
74 {
75 cardId = splitKey[1];
76 }
77 }
78
79 return cardId;
80 }
81 }