File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from time import time , sleep
2+ from diskcache import FanoutCache
3+
4+ # Initialise the maximum delay reference
5+ max_delay = 0
6+
7+ # Initialise the reference to current time
8+ # Add a significant amount of time to ignore the first measurement due to other initialisations
9+ current_time = time () + 100
10+
11+ # Initialise the Fanout Cache instance
12+ data = FanoutCache ('test' , shards = 8 )
13+
14+
15+ # Declare the function used to modify the data
16+ def set_data (** kwargs ):
17+ """
18+
19+ Function used to modify the cache.
20+
21+ :param kwargs: Key, value pairs of data to modify.
22+
23+ """
24+
25+ # Fetch the global variables
26+ global max_delay
27+ global current_time
28+ global data
29+
30+ # Update the data with the given keyword arguments
31+ for key , value in kwargs .items ():
32+
33+ # Measure the time taken to update it for each item
34+ temp = time ()
35+ dif = temp - current_time
36+ if dif > max_delay :
37+ max_delay = dif
38+ print ("New max delay encountered: " , max_delay )
39+ current_time = temp
40+
41+ # Update the data
42+ data [key ] = value
43+
44+
45+ # Initialise some test values
46+ test_values = {str (key ): value for key in range (25 ) for value in range (25 )}
47+
48+ # Keep writing the data in 0.1 sec intervals
49+ while True :
50+ sleep (0.1 )
51+ set_data (** test_values )
You can’t perform that action at this time.
0 commit comments