|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef CACHEMGR_H |
|
17 #define CACHEMGR_H |
|
18 |
|
19 #include <e32base.h> |
|
20 #include "log.h" |
|
21 #include "panic.h" |
|
22 #include "srvdefs.h" |
|
23 #include <f32file.h> |
|
24 |
|
25 _LIT(KCacheMgrIniFile, "centrep.ini"); |
|
26 |
|
27 #ifndef DEFAULT_CENTREP_CACHE_SIZE |
|
28 /** |
|
29 The default size of the coarse-grained cache, used when there is no .ini setting defined. |
|
30 The default value is approximately the size needed to cache everything during device boot-up |
|
31 @internalComponent |
|
32 */ |
|
33 #define DEFAULT_CENTREP_CACHE_SIZE 100000 |
|
34 #else |
|
35 #if DEFAULT_CENTREP_CACHE_SIZE <= 0 |
|
36 #error "DEFAULT_CENTREP_CACHE_SIZE macro value must be greater than 0" |
|
37 #endif |
|
38 #endif |
|
39 |
|
40 /** |
|
41 The default size of the coarse-grained cache. |
|
42 @internalComponent |
|
43 */ |
|
44 const TInt KDefaultCacheSize=DEFAULT_CENTREP_CACHE_SIZE; |
|
45 |
|
46 /** |
|
47 The special cache size value used for enabling the cache without changing the current cache size value. |
|
48 @internalComponent |
|
49 */ |
|
50 const TInt KInvalidCacheSize = -1; |
|
51 |
|
52 #ifndef DEFAULT_CENTREP_CACHE_EVICTION_TIMEOUT |
|
53 /** |
|
54 The default timeout value of the coarse-grained cache, used when there is no .ini setting defined. |
|
55 The default value is approximately the timeout needed to keep everything in cache during device boot-up |
|
56 @internalComponent |
|
57 */ |
|
58 // If this value will need to be changed, please ensure the KTimeoutToSizeConversion is adjusted accordingly. |
|
59 #define DEFAULT_CENTREP_CACHE_EVICTION_TIMEOUT 120000000 |
|
60 #else |
|
61 #if DEFAULT_CENTREP_CACHE_EVICTION_TIMEOUT <= 0 |
|
62 #error "DEFAULT_CENTREP_CACHE_EVICTION_TIMEOUT macro value must be greater than 0" |
|
63 #endif |
|
64 #endif |
|
65 |
|
66 /** |
|
67 The default timeout value (in microseconds) for the coarse-grained cache repository eviction. |
|
68 @internalComponent |
|
69 */ |
|
70 const TInt KDefaultEvictionTimeout=DEFAULT_CENTREP_CACHE_EVICTION_TIMEOUT; |
|
71 |
|
72 /** |
|
73 The constant used in forced evicition sorting algorithm for converting microsecond-based timeout |
|
74 values to an intermediary unit compatible with byte-based size values. |
|
75 @internalComponent |
|
76 */ |
|
77 const TInt KTimeoutToSizeConversion=DEFAULT_CENTREP_CACHE_EVICTION_TIMEOUT/(100000*24); |
|
78 |
|
79 /** |
|
80 The special timeout value used for enabling the cache without changing the current timeout value. |
|
81 @internalComponent |
|
82 */ |
|
83 const TInt KInvalidEvictionTimeout=-1; |
|
84 |
|
85 |
|
86 class CSharedRepository; |
|
87 |
|
88 /** |
|
89 @internalTechnology |
|
90 This is the class which manages Coarse-Grained cache operations including delayed-unloading of |
|
91 repositories and forced eviction of repositories under OOM conditions. |
|
92 */ |
|
93 class CRepositoryCacheManager : public CTimer |
|
94 { |
|
95 friend class TRepositoryCacheManagerTester; |
|
96 public: |
|
97 static CRepositoryCacheManager* NewLC(RFs& aFs); |
|
98 ~CRepositoryCacheManager(); |
|
99 void ConstructL(RFs& aFs); |
|
100 |
|
101 void EnableCache(); |
|
102 void DisableCache(TBool aFullFlush = EFalse); |
|
103 void EnableCache(TInt aDefaultTimeout, TInt aCacheSize); |
|
104 |
|
105 inline TBool Enabled(); |
|
106 |
|
107 TBool StartEviction(CSharedRepository*& aRepository); |
|
108 |
|
109 void RemoveIdleRepository(CSharedRepository* aRepository); |
|
110 void FlushCache(TBool aFullFlush = ETrue); |
|
111 |
|
112 protected: |
|
113 /** |
|
114 @internalTechnology |
|
115 This is the class/structure which keeps eviction-related cache data |
|
116 */ |
|
117 class TRepositoryCacheInfo |
|
118 { |
|
119 public: |
|
120 TTime iCacheTime; |
|
121 CSharedRepository* iSharedRepository; |
|
122 }; |
|
123 |
|
124 void RunL(); |
|
125 |
|
126 private: |
|
127 inline CRepositoryCacheManager(); |
|
128 |
|
129 void Evict(TInt aIdleRepIndex); |
|
130 void RescheduleTimer(const TTime& aTimeInUTC); |
|
131 |
|
132 static TInt ForcedEvictionSortOrder(const TRepositoryCacheInfo &aRepository1, const TRepositoryCacheInfo &aRepository2); |
|
133 static TInt TimerEvictionSortOrder(const TRepositoryCacheInfo &aRepository1, const TRepositoryCacheInfo &aRepository2); |
|
134 |
|
135 private: |
|
136 TBool iEnabled; |
|
137 TInt iTotalCacheUsage; |
|
138 RArray<TRepositoryCacheInfo> iIdleRepositories; |
|
139 TTimeIntervalMicroSeconds32 iDefaultTimeout; |
|
140 TInt iCacheSize; |
|
141 }; |
|
142 |
|
143 #include "cachemgr.inl" |
|
144 |
|
145 #endif // CACHEMGR_H |