@@ -5,14 +5,14 @@ import (
55 "time"
66)
77
8- // CacheEntry представляет запись в кэше
8+ // CacheEntry represents a cache entry
99type CacheEntry struct {
1010 Value interface {}
1111 ExpiresAt time.Time
1212 CreatedAt time.Time
1313}
1414
15- // Cache представляет простой in-memory кэш с TTL
15+ // Cache represents a simple in-memory cache with TTL
1616type Cache struct {
1717 data map [string ]* CacheEntry
1818 mutex sync.RWMutex
@@ -22,15 +22,15 @@ type Cache struct {
2222 misses int64
2323}
2424
25- // NewCache создает новый экземпляр кэша
25+ // NewCache creates a new cache instance
2626func NewCache (ttl time.Duration ) * Cache {
2727 return & Cache {
2828 data : make (map [string ]* CacheEntry ),
2929 ttl : ttl ,
3030 }
3131}
3232
33- // Get получает значение из кэша
33+ // Get retrieves a value from the cache
3434func (c * Cache ) Get (key string ) (interface {}, bool ) {
3535 c .mutex .RLock ()
3636 entry , exists := c .data [key ]
@@ -41,7 +41,7 @@ func (c *Cache) Get(key string) (interface{}, bool) {
4141 return nil , false
4242 }
4343
44- // Проверяем TTL
44+ // Check TTL
4545 if time .Now ().After (entry .ExpiresAt ) {
4646 c .mutex .Lock ()
4747 delete (c .data , key )
@@ -55,7 +55,7 @@ func (c *Cache) Get(key string) (interface{}, bool) {
5555 return entry .Value , true
5656}
5757
58- // Set устанавливает значение в кэш
58+ // Set sets a value in the cache
5959func (c * Cache ) Set (key string , value interface {}) {
6060 c .mutex .Lock ()
6161 defer c .mutex .Unlock ()
@@ -67,35 +67,35 @@ func (c *Cache) Set(key string, value interface{}) {
6767 }
6868}
6969
70- // Delete удаляет запись из кэша
70+ // Delete removes an entry from the cache
7171func (c * Cache ) Delete (key string ) {
7272 c .mutex .Lock ()
7373 defer c .mutex .Unlock ()
7474 delete (c .data , key )
7575}
7676
77- // Clear очищает весь кэш
77+ // Clear clears the entire cache
7878func (c * Cache ) Clear () {
7979 c .mutex .Lock ()
8080 defer c .mutex .Unlock ()
8181 c .data = make (map [string ]* CacheEntry )
8282}
8383
84- // Size возвращает размер кэша
84+ // Size returns the cache size
8585func (c * Cache ) Size () int {
8686 c .mutex .RLock ()
8787 defer c .mutex .RUnlock ()
8888 return len (c .data )
8989}
9090
91- // Stats возвращает статистику кэша
91+ // Stats returns cache statistics
9292func (c * Cache ) Stats () (hits , misses , evicted , size int64 ) {
9393 c .mutex .RLock ()
9494 defer c .mutex .RUnlock ()
9595 return c .hits , c .misses , c .evicted , int64 (len (c .data ))
9696}
9797
98- // Cleanup удаляет истекшие записи
98+ // Cleanup removes expired entries
9999func (c * Cache ) Cleanup () {
100100 c .mutex .Lock ()
101101 defer c .mutex .Unlock ()
@@ -109,7 +109,7 @@ func (c *Cache) Cleanup() {
109109 }
110110}
111111
112- // StartCleanup запускает автоматическую очистку кэша
112+ // StartCleanup starts automatic cache cleanup
113113func (c * Cache ) StartCleanup (interval time.Duration ) {
114114 ticker := time .NewTicker (interval )
115115 go func () {
@@ -123,24 +123,24 @@ func (c *Cache) StartCleanup(interval time.Duration) {
123123 }()
124124}
125125
126- // NodeCache специализированный кэш для информации о нодах
126+ // NodeCache specialized cache for node information
127127type NodeCache struct {
128128 cache * Cache
129129 nodeMutex sync.RWMutex
130- nodes map [string ]NodeInfo // Кэш последней информации о ноде
130+ nodes map [string ]NodeInfo // Cache of the latest node information
131131}
132132
133- // NewNodeCache создает новый кэш нод
133+ // NewNodeCache creates a new node cache
134134func NewNodeCache (ttl time.Duration ) * NodeCache {
135135 return & NodeCache {
136136 cache : NewCache (ttl ),
137137 nodes : make (map [string ]NodeInfo ),
138138 }
139139}
140140
141- // GetNodeInfo получает информацию о ноде из кэша
141+ // GetNodeInfo retrieves node information from the cache
142142func (nc * NodeCache ) GetNodeInfo (ip string ) (NodeInfo , bool ) {
143- // Сначала проверяем кэш в памяти
143+ // First check the in-memory cache
144144 nc .nodeMutex .RLock ()
145145 node , exists := nc .nodes [ip ]
146146 nc .nodeMutex .RUnlock ()
@@ -149,10 +149,10 @@ func (nc *NodeCache) GetNodeInfo(ip string) (NodeInfo, bool) {
149149 return node , true
150150 }
151151
152- // Проверяем общий кэш
152+ // Check the general cache
153153 if cached , found := nc .cache .Get ("node:" + ip ); found {
154154 if nodeInfo , ok := cached .(NodeInfo ); ok {
155- // Сохраняем в локальный кэш
155+ // Save to local cache
156156 nc .nodeMutex .Lock ()
157157 nc .nodes [ip ] = nodeInfo
158158 nc .nodeMutex .Unlock ()
@@ -163,7 +163,7 @@ func (nc *NodeCache) GetNodeInfo(ip string) (NodeInfo, bool) {
163163 return NodeInfo {}, false
164164}
165165
166- // SetNodeInfo сохраняет информацию о ноде в кэш
166+ // SetNodeInfo saves node information to the cache
167167func (nc * NodeCache ) SetNodeInfo (ip string , node NodeInfo ) {
168168 nc .nodeMutex .Lock ()
169169 nc .nodes [ip ] = node
@@ -172,7 +172,7 @@ func (nc *NodeCache) SetNodeInfo(ip string, node NodeInfo) {
172172 nc .cache .Set ("node:" + ip , node )
173173}
174174
175- // InvalidateNodeInfo удаляет информацию о ноде из кэша
175+ // InvalidateNodeInfo removes node information from the cache
176176func (nc * NodeCache ) InvalidateNodeInfo (ip string ) {
177177 nc .nodeMutex .Lock ()
178178 delete (nc .nodes , ip )
@@ -181,19 +181,19 @@ func (nc *NodeCache) InvalidateNodeInfo(ip string) {
181181 nc .cache .Delete ("node:" + ip )
182182}
183183
184- // HardwareCache специализированный кэш для информации об оборудовании
184+ // HardwareCache specialized cache for hardware information
185185type HardwareCache struct {
186186 cache * Cache
187187}
188188
189- // NewHardwareCache создает новый кэш оборудования
189+ // NewHardwareCache creates a new hardware cache
190190func NewHardwareCache (ttl time.Duration ) * HardwareCache {
191191 return & HardwareCache {
192192 cache : NewCache (ttl ),
193193 }
194194}
195195
196- // GetHardwareInfo получает информацию об оборудовании из кэша
196+ // GetHardwareInfo retrieves hardware information from the cache
197197func (hc * HardwareCache ) GetHardwareInfo (ip string ) (Hardware , bool ) {
198198 if cached , found := hc .cache .Get ("hardware:" + ip ); found {
199199 if hardware , ok := cached .(Hardware ); ok {
@@ -203,43 +203,43 @@ func (hc *HardwareCache) GetHardwareInfo(ip string) (Hardware, bool) {
203203 return Hardware {}, false
204204}
205205
206- // SetHardwareInfo сохраняет информацию об оборудовании в кэш
206+ // SetHardwareInfo saves hardware information to the cache
207207func (hc * HardwareCache ) SetHardwareInfo (ip string , hardware Hardware ) {
208208 hc .cache .Set ("hardware:" + ip , hardware )
209209}
210210
211- // InvalidateHardwareInfo удаляет информацию об оборудовании из кэша
211+ // InvalidateHardwareInfo removes hardware information from the cache
212212func (hc * HardwareCache ) InvalidateHardwareInfo (ip string ) {
213213 hc .cache .Delete ("hardware:" + ip )
214214}
215215
216- // ConfigCache кэш для конфигурационных файлов
216+ // ConfigCache cache for configuration files
217217type ConfigCache struct {
218218 cache * Cache
219219}
220220
221- // NewConfigCache создает новый кэш конфигураций
221+ // NewConfigCache creates a new configuration cache
222222func NewConfigCache (ttl time.Duration ) * ConfigCache {
223223 return & ConfigCache {
224224 cache : NewCache (ttl ),
225225 }
226226}
227227
228- // GetConfig получает конфигурацию из кэша
228+ // GetConfig retrieves configuration from the cache
229229func (cc * ConfigCache ) GetConfig (clusterName , configType string ) (interface {}, bool ) {
230230 key := clusterName + ":" + configType
231231 return cc .cache .Get (key )
232232}
233233
234- // SetConfig сохраняет конфигурацию в кэш
234+ // SetConfig saves configuration to the cache
235235func (cc * ConfigCache ) SetConfig (clusterName , configType string , config interface {}) {
236236 key := clusterName + ":" + configType
237237 cc .cache .Set (key , config )
238238}
239239
240- // InvalidateClusterConfig удаляет все конфигурации кластера из кэша
240+ // InvalidateClusterConfig removes all cluster configurations from the cache
241241func (cc * ConfigCache ) InvalidateClusterConfig (clusterName string ) {
242- // Упрощенная реализация - в реальном приложении можно использовать префиксы
242+ // Simplified implementation - in a real application, prefixes can be used
243243 // для более эффективного удаления
244244 cc .cache .Clear ()
245245}
0 commit comments