3232
3333#include " FileBlobCache.h"
3434
35+ #include < com_android_graphics_egl_flags.h>
36+
37+ using namespace com ::android::graphics::egl;
38+
3539namespace android {
3640
3741constexpr uint32_t kMultifileBlobCacheVersion = 2 ;
@@ -45,9 +49,9 @@ struct MultifileHeader {
4549};
4650
4751struct MultifileEntryStats {
52+ uint32_t entryHash;
4853 EGLsizeiANDROID valueSize;
4954 size_t fileSize;
50- time_t accessTime;
5155};
5256
5357struct MultifileStatus {
@@ -100,6 +104,26 @@ class DeferredTask {
100104 size_t mBufferSize ;
101105};
102106
107+ #if COM_ANDROID_GRAPHICS_EGL_FLAGS(MULTIFILE_BLOBCACHE_ADVANCED_USAGE)
108+ struct MultifileTimeLess {
109+ bool operator ()(const struct timespec & t1, const struct timespec & t2) const {
110+ if (t1.tv_sec == t2.tv_sec ) {
111+ // If seconds are equal, check nanoseconds
112+ return t1.tv_nsec < t2.tv_nsec ;
113+ } else {
114+ // Otherwise, compare seconds
115+ return t1.tv_sec < t2.tv_sec ;
116+ }
117+ }
118+ };
119+
120+ // The third parameter here causes all entries to be sorted by access time,
121+ // so oldest will be accessed first in applyLRU
122+ using MultifileEntryStatsMap =
123+ std::multimap<struct timespec , MultifileEntryStats, MultifileTimeLess>;
124+ using MultifileEntryStatsMapIter = MultifileEntryStatsMap::iterator;
125+ #endif // COM_ANDROID_GRAPHICS_EGL_FLAGS(MULTIFILE_BLOBCACHE_ADVANCED_USAGE)
126+
103127class MultifileBlobCache {
104128public:
105129 MultifileBlobCache (size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize,
@@ -115,6 +139,7 @@ class MultifileBlobCache {
115139
116140 size_t getTotalSize () const { return mTotalCacheSize ; }
117141 size_t getTotalEntries () const { return mTotalCacheEntries ; }
142+ size_t getTotalCacheSizeDivisor () const { return mTotalCacheSizeDivisor ; }
118143
119144 const std::string& getCurrentBuildId () const { return mBuildId ; }
120145 void setCurrentBuildId (const std::string& buildId) { mBuildId = buildId; }
@@ -124,10 +149,11 @@ class MultifileBlobCache {
124149
125150private:
126151 void trackEntry (uint32_t entryHash, EGLsizeiANDROID valueSize, size_t fileSize,
127- time_t accessTime);
152+ const timespec& accessTime);
128153 bool contains (uint32_t entryHash) const ;
129154 bool removeEntry (uint32_t entryHash);
130155 MultifileEntryStats getEntryStats (uint32_t entryHash);
156+ void updateEntryTime (uint32_t entryHash, const timespec& newTime);
131157
132158 bool createStatus (const std::string& baseDir);
133159 bool checkStatus (const std::string& baseDir);
@@ -151,8 +177,14 @@ class MultifileBlobCache {
151177 std::string mBuildId ;
152178 uint32_t mCacheVersion ;
153179
180+ #if COM_ANDROID_GRAPHICS_EGL_FLAGS(MULTIFILE_BLOBCACHE_ADVANCED_USAGE)
181+ std::unordered_map<uint32_t , MultifileEntryStatsMapIter> mEntries ;
182+ MultifileEntryStatsMap mEntryStats ;
183+ #else
154184 std::unordered_set<uint32_t > mEntries ;
155185 std::unordered_map<uint32_t , MultifileEntryStats> mEntryStats ;
186+ #endif // COM_ANDROID_GRAPHICS_EGL_FLAGS(MULTIFILE_BLOBCACHE_ADVANCED_USAGE)
187+
156188 std::unordered_map<uint32_t , MultifileHotCache> mHotCache ;
157189
158190 size_t mMaxKeySize ;
@@ -161,6 +193,7 @@ class MultifileBlobCache {
161193 size_t mMaxTotalEntries ;
162194 size_t mTotalCacheSize ;
163195 size_t mTotalCacheEntries ;
196+ size_t mTotalCacheSizeDivisor ;
164197 size_t mHotCacheLimit ;
165198 size_t mHotCacheEntryLimit ;
166199 size_t mHotCacheSize ;
0 commit comments