-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcas
More file actions
52 lines (33 loc) · 663 Bytes
/
cas
File metadata and controls
52 lines (33 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
CACHE = {}
def set(key, value):
CACHE[key] = value
return True
def get(key):
return CACHE.get(key)
def delete(key):
if key in CACHE:
del CACHE[key]
def flush():
CACHE.clear()
def gets(key):
v = CACHE.get(key)
if v:
return v, hash(repr(v))
def cas(key, value, cas_unique):
r = gets(key)
if r:
val, unique = r
if unique == cas_unique:
return set(key, value)
else:
return False
print set('x', 1)
print get('x')
print get('y')
delete('x')
print get('x')
set('x', 2)
print gets('x')
print cas('x', 3, 0)
print cas('x', 5, 6400019251)
print get('x')