@@ -13,16 +13,14 @@ module Cardano.DbSync.Cache.Types (
13
13
CacheEpoch (.. ),
14
14
CacheInternal (.. ),
15
15
EpochBlockDiff (.. ),
16
+ StakeCache (.. ),
16
17
StakePoolCache ,
17
18
18
19
-- * Inits
19
20
useNoCache ,
20
21
initCacheStatistics ,
21
22
newEmptyCache ,
22
23
23
- -- * Helpers
24
- isCacheActionUpdate ,
25
-
26
24
-- * CacheStatistics
27
25
CacheStatistics (.. ),
28
26
textShowStats ,
@@ -49,6 +47,11 @@ import Ouroboros.Consensus.Cardano.Block (StandardCrypto)
49
47
50
48
type StakePoolCache = Map PoolKeyHash DB. PoolHashId
51
49
50
+ data StakeCache = StakeCache
51
+ { scStableCache :: ! (Map StakeCred DB. StakeAddressId )
52
+ , scLruCache :: ! (LRUCache StakeCred DB. StakeAddressId )
53
+ }
54
+
52
55
-- 'CacheStatus' enables functions in this module to be called even if the cache has not been initialized.
53
56
-- This is used during genesis insertions, where the cache is not yet initiated, and when the user has disabled the cache functionality.
54
57
data CacheStatus
@@ -57,12 +60,13 @@ data CacheStatus
57
60
58
61
data CacheAction
59
62
= UpdateCache
63
+ | UpdateCacheStrong
60
64
| DoNotUpdateCache
61
65
| EvictAndUpdateCache
62
66
deriving (Eq )
63
67
64
68
data CacheInternal = CacheInternal
65
- { cStakeRawHashes :: ! (StrictTVar IO ( LRUCache StakeCred DB. StakeAddressId ) )
69
+ { cStake :: ! (StrictTVar IO StakeCache )
66
70
, cPools :: ! (StrictTVar IO StakePoolCache )
67
71
, cDatum :: ! (StrictTVar IO (LRUCache DataHash DB. DatumId ))
68
72
, cMultiAssets :: ! (StrictTVar IO (LRUCache (PolicyID StandardCrypto , AssetName ) DB. MultiAssetId ))
@@ -89,7 +93,7 @@ data CacheStatistics = CacheStatistics
89
93
90
94
-- CacheCapacity is used to define capacities for different types of cache entries.
91
95
data CacheCapacity = CacheCapacity
92
- { cacheCapacityStakeHashRaw :: ! Word64
96
+ { cacheCapacityStake :: ! Word64
93
97
, cacheCapacityDatum :: ! Word64
94
98
, cacheCapacityMultiAsset :: ! Word64
95
99
, cacheCapacityTx :: ! Word64
@@ -118,7 +122,7 @@ textShowStats :: CacheStatus -> IO Text
118
122
textShowStats NoCache = pure " NoCache"
119
123
textShowStats (ActiveCache ic) = do
120
124
stats <- readTVarIO $ cStats ic
121
- stakeHashRaws <- readTVarIO (cStakeRawHashes ic)
125
+ stakeHashRaws <- readTVarIO (cStake ic)
122
126
pools <- readTVarIO (cPools ic)
123
127
datums <- readTVarIO (cDatum ic)
124
128
mAssets <- readTVarIO (cMultiAssets ic)
@@ -127,8 +131,10 @@ textShowStats (ActiveCache ic) = do
127
131
mconcat
128
132
[ " \n Cache Statistics:"
129
133
, " \n Stake Addresses: "
130
- , " cache size: "
131
- , textShow (LRU. getCapacity stakeHashRaws)
134
+ , " cache sizes: "
135
+ , textShow (Map. size $ scStableCache stakeHashRaws)
136
+ , " and "
137
+ , textShow (LRU. getSize $ scLruCache stakeHashRaws)
132
138
, if credsQueries stats == 0
133
139
then " "
134
140
else " , hit rate: " <> textShow (100 * credsHits stats `div` credsQueries stats) <> " %"
@@ -197,7 +203,7 @@ useNoCache = NoCache
197
203
198
204
newEmptyCache :: MonadIO m => CacheCapacity -> m CacheStatus
199
205
newEmptyCache CacheCapacity {.. } = liftIO $ do
200
- cStakeRawHashes <- newTVarIO (LRU. empty cacheCapacityStakeHashRaw )
206
+ cStake <- newTVarIO (StakeCache Map. empty ( LRU. empty cacheCapacityStake) )
201
207
cPools <- newTVarIO Map. empty
202
208
cDatum <- newTVarIO (LRU. empty cacheCapacityDatum)
203
209
cMultiAssets <- newTVarIO (LRU. empty cacheCapacityMultiAsset)
@@ -208,7 +214,7 @@ newEmptyCache CacheCapacity {..} = liftIO $ do
208
214
209
215
pure . ActiveCache $
210
216
CacheInternal
211
- { cStakeRawHashes = cStakeRawHashes
217
+ { cStake = cStake
212
218
, cPools = cPools
213
219
, cDatum = cDatum
214
220
, cMultiAssets = cMultiAssets
@@ -223,7 +229,3 @@ initCacheStatistics = CacheStatistics 0 0 0 0 0 0 0 0 0 0 0 0
223
229
224
230
initCacheEpoch :: CacheEpoch
225
231
initCacheEpoch = CacheEpoch mempty Nothing
226
-
227
- isCacheActionUpdate :: CacheAction -> Bool
228
- isCacheActionUpdate UpdateCache = True
229
- isCacheActionUpdate _other = False
0 commit comments