Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
jussi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
jussi
Commits
ba9906ae
Unverified
Commit
ba9906ae
authored
5 years ago
by
Justin Welch
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #225 from steemit/dont-cache-forever
Dont cache irreversible blocks forever
parents
d92287df
a0899525
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
jussi/cache/cache_group.py
+3
-3
3 additions, 3 deletions
jussi/cache/cache_group.py
jussi/cache/ttl.py
+3
-3
3 additions, 3 deletions
jussi/cache/ttl.py
jussi/cache/utils.py
+0
-2
0 additions, 2 deletions
jussi/cache/utils.py
tests/test_ttls.py
+7
-7
7 additions, 7 deletions
tests/test_ttls.py
with
13 additions
and
15 deletions
jussi/cache/cache_group.py
+
3
−
3
View file @
ba9906ae
...
@@ -33,7 +33,7 @@ from .utils import merge_cached_responses
...
@@ -33,7 +33,7 @@ from .utils import merge_cached_responses
logger
=
structlog
.
getLogger
(
__name__
)
logger
=
structlog
.
getLogger
(
__name__
)
BATCH_IRREVERSIBLE_TTL_SET
=
frozenset
([
TTL
.
NO
_EXPIRE_IF_IRREVERSIBLE
])
BATCH_IRREVERSIBLE_TTL_SET
=
frozenset
([
TTL
.
DEFAULT
_EXPIRE_IF_IRREVERSIBLE
])
# types
# types
CacheTTLValue
=
TypeVar
(
'
CacheTTL
'
,
int
,
float
,
type
(
None
))
CacheTTLValue
=
TypeVar
(
'
CacheTTL
'
,
int
,
float
,
type
(
None
))
...
@@ -188,7 +188,7 @@ class CacheGroup:
...
@@ -188,7 +188,7 @@ class CacheGroup:
)
->
None
:
)
->
None
:
key
=
jsonrpc_cache_key
(
request
)
key
=
jsonrpc_cache_key
(
request
)
ttl
=
ttl
or
request
.
upstream
.
ttl
ttl
=
ttl
or
request
.
upstream
.
ttl
if
ttl
==
TTL
.
NO
_EXPIRE_IF_IRREVERSIBLE
:
if
ttl
==
TTL
.
DEFAULT
_EXPIRE_IF_IRREVERSIBLE
:
last_irreversible_block_num
=
last_irreversible_block_num
or
\
last_irreversible_block_num
=
last_irreversible_block_num
or
\
self
.
_memory_cache
.
gets
(
'
last_irreversible_block_num
'
)
or
\
self
.
_memory_cache
.
gets
(
'
last_irreversible_block_num
'
)
or
\
await
self
.
get
(
'
last_irreversible_block_num
'
)
await
self
.
get
(
'
last_irreversible_block_num
'
)
...
@@ -218,7 +218,7 @@ class CacheGroup:
...
@@ -218,7 +218,7 @@ class CacheGroup:
else
:
else
:
new_ttls
=
[]
new_ttls
=
[]
for
i
,
ttl
in
enumerate
(
ttls
):
for
i
,
ttl
in
enumerate
(
ttls
):
if
ttl
==
TTL
.
NO
_EXPIRE_IF_IRREVERSIBLE
:
if
ttl
==
TTL
.
DEFAULT
_EXPIRE_IF_IRREVERSIBLE
:
ttl
=
irreversible_ttl
(
responses
[
i
],
last_irreversible_block_num
)
ttl
=
irreversible_ttl
(
responses
[
i
],
last_irreversible_block_num
)
new_ttls
.
append
(
ttl
)
new_ttls
.
append
(
ttl
)
triplets
=
filter
(
lambda
p
:
p
[
0
]
!=
TTL
.
NO_CACHE
,
zip
(
ttls
,
requests
,
responses
))
triplets
=
filter
(
lambda
p
:
p
[
0
]
!=
TTL
.
NO_CACHE
,
zip
(
ttls
,
requests
,
responses
))
...
...
This diff is collapsed.
Click to expand it.
jussi/cache/ttl.py
+
3
−
3
View file @
ba9906ae
...
@@ -8,11 +8,11 @@ Method Settings
...
@@ -8,11 +8,11 @@ Method Settings
- TTL is an integer value in seconds. Integers <= 0 have special meaning
- TTL is an integer value in seconds. Integers <= 0 have special meaning
- A TTL of `0` won
'
t expire
- A TTL of `0` won
'
t expire
- A TTL of `-1` wont be cached
- A TTL of `-1` wont be cached
- A TTL of `-2` will be cached with
ou
t expiration only if it is
'
irreversible
'
in terms of blockchain consesus
- A TTL of `-2` will be cached with
defaul
t expiration only if it is
'
irreversible
'
in terms of blockchain consesus
- For readabilty/writabilty, there are shorthand variables for these
'
special
'
TTL values:
- For readabilty/writabilty, there are shorthand variables for these
'
special
'
TTL values:
- `NO_EXPIRE` == 0
- `NO_EXPIRE` == 0
- `NO_CACHE` == -1
- `NO_CACHE` == -1
- `
NO
_EXPIRE_IF_IRREVERSIBLE` == -2
- `
DEFAULT
_EXPIRE_IF_IRREVERSIBLE` == -2
"""
"""
...
@@ -23,7 +23,7 @@ class TTL(Enum):
...
@@ -23,7 +23,7 @@ class TTL(Enum):
DEFAULT_TTL
=
3
DEFAULT_TTL
=
3
NO_EXPIRE
=
None
NO_EXPIRE
=
None
NO_CACHE
=
-
1
NO_CACHE
=
-
1
NO
_EXPIRE_IF_IRREVERSIBLE
=
-
2
DEFAULT
_EXPIRE_IF_IRREVERSIBLE
=
-
2
# pylint: disable=no-else-return
# pylint: disable=no-else-return
def
__eq__
(
self
,
other
:
int
)
->
bool
:
def
__eq__
(
self
,
other
:
int
)
->
bool
:
...
...
This diff is collapsed.
Click to expand it.
jussi/cache/utils.py
+
0
−
2
View file @
ba9906ae
...
@@ -30,8 +30,6 @@ def irreversible_ttl(jsonrpc_response: dict=None,
...
@@ -30,8 +30,6 @@ def irreversible_ttl(jsonrpc_response: dict=None,
return
TTL
.
NO_CACHE
return
TTL
.
NO_CACHE
try
:
try
:
jrpc_block_num
=
block_num_from_jsonrpc_response
(
jsonrpc_response
)
jrpc_block_num
=
block_num_from_jsonrpc_response
(
jsonrpc_response
)
if
jrpc_block_num
and
jrpc_block_num
<=
last_irreversible_block_num
:
return
TTL
.
NO_EXPIRE
return
TTL
.
DEFAULT_TTL
return
TTL
.
DEFAULT_TTL
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
warning
(
logger
.
warning
(
...
...
This diff is collapsed.
Click to expand it.
tests/test_ttls.py
+
7
−
7
View file @
ba9906ae
...
@@ -35,8 +35,8 @@ non_ttl_rpc_req = jsonrpc_from_request(dummy_request, 0, {"id": "1", "jsonrpc":
...
@@ -35,8 +35,8 @@ non_ttl_rpc_req = jsonrpc_from_request(dummy_request, 0, {"id": "1", "jsonrpc":
(
ttl_rpc_req
,
rpc_resp
,
999
,
TTL
.
DEFAULT_TTL
),
(
ttl_rpc_req
,
rpc_resp
,
999
,
TTL
.
DEFAULT_TTL
),
# cache when last_block_num >= response block_num
# cache when last_block_num >= response block_num
(
ttl_rpc_req
,
rpc_resp
,
1000
,
TTL
.
NO_EXPIRE
),
(
ttl_rpc_req
,
rpc_resp
,
1000
,
TTL
.
DEFAULT_TTL
),
(
ttl_rpc_req
,
rpc_resp
,
1001
,
TTL
.
NO_EXPIRE
),
(
ttl_rpc_req
,
rpc_resp
,
1001
,
TTL
.
DEFAULT_TTL
),
# don't cache when bad/missing response block_num
# don't cache when bad/missing response block_num
(
ttl_rpc_req
,
{},
2000
,
TTL
.
NO_CACHE
),
(
ttl_rpc_req
,
{},
2000
,
TTL
.
NO_CACHE
),
...
@@ -54,7 +54,7 @@ def test_ttls(rpc_req, rpc_resp, last_block_num, expected):
...
@@ -54,7 +54,7 @@ def test_ttls(rpc_req, rpc_resp, last_block_num, expected):
(
TTL
.
NO_CACHE
,
-
1
),
(
TTL
.
NO_CACHE
,
-
1
),
(
TTL
.
DEFAULT_TTL
,
3
),
(
TTL
.
DEFAULT_TTL
,
3
),
(
TTL
.
NO_EXPIRE
,
None
),
(
TTL
.
NO_EXPIRE
,
None
),
(
TTL
.
NO
_EXPIRE_IF_IRREVERSIBLE
,
-
2
),
(
TTL
.
DEFAULT
_EXPIRE_IF_IRREVERSIBLE
,
-
2
),
]
]
)
)
def
test_ttl_eq
(
ttl
,
eq
):
def
test_ttl_eq
(
ttl
,
eq
):
...
@@ -65,7 +65,7 @@ def test_ttl_eq(ttl, eq):
...
@@ -65,7 +65,7 @@ def test_ttl_eq(ttl, eq):
@pytest.mark.parametrize
(
'
ttl
'
,
[
@pytest.mark.parametrize
(
'
ttl
'
,
[
(
TTL
.
NO_CACHE
),
(
TTL
.
NO_CACHE
),
(
TTL
.
DEFAULT_TTL
),
(
TTL
.
DEFAULT_TTL
),
(
TTL
.
NO
_EXPIRE_IF_IRREVERSIBLE
)
(
TTL
.
DEFAULT
_EXPIRE_IF_IRREVERSIBLE
)
]
]
)
)
def
test_ttl_gt
(
ttl
):
def
test_ttl_gt
(
ttl
):
...
@@ -75,7 +75,7 @@ def test_ttl_gt(ttl):
...
@@ -75,7 +75,7 @@ def test_ttl_gt(ttl):
@pytest.mark.parametrize
(
'
ttl
'
,
[
@pytest.mark.parametrize
(
'
ttl
'
,
[
(
TTL
.
NO_CACHE
),
(
TTL
.
NO_CACHE
),
(
TTL
.
DEFAULT_TTL
),
(
TTL
.
DEFAULT_TTL
),
(
TTL
.
NO
_EXPIRE_IF_IRREVERSIBLE
)
(
TTL
.
DEFAULT
_EXPIRE_IF_IRREVERSIBLE
)
]
]
)
)
def
test_ttl_ge
(
ttl
):
def
test_ttl_ge
(
ttl
):
...
@@ -85,7 +85,7 @@ def test_ttl_ge(ttl):
...
@@ -85,7 +85,7 @@ def test_ttl_ge(ttl):
@pytest.mark.parametrize
(
'
ttl
'
,
[
@pytest.mark.parametrize
(
'
ttl
'
,
[
(
TTL
.
NO_CACHE
),
(
TTL
.
NO_CACHE
),
(
TTL
.
DEFAULT_TTL
),
(
TTL
.
DEFAULT_TTL
),
(
TTL
.
NO
_EXPIRE_IF_IRREVERSIBLE
)
(
TTL
.
DEFAULT
_EXPIRE_IF_IRREVERSIBLE
)
]
]
)
)
def
test_ttl_lt
(
ttl
):
def
test_ttl_lt
(
ttl
):
...
@@ -95,7 +95,7 @@ def test_ttl_lt(ttl):
...
@@ -95,7 +95,7 @@ def test_ttl_lt(ttl):
@pytest.mark.parametrize
(
'
ttl
'
,
[
@pytest.mark.parametrize
(
'
ttl
'
,
[
(
TTL
.
NO_CACHE
),
(
TTL
.
NO_CACHE
),
(
TTL
.
DEFAULT_TTL
),
(
TTL
.
DEFAULT_TTL
),
(
TTL
.
NO
_EXPIRE_IF_IRREVERSIBLE
)
(
TTL
.
DEFAULT
_EXPIRE_IF_IRREVERSIBLE
)
]
]
)
)
def
test_ttl_le
(
ttl
):
def
test_ttl_le
(
ttl
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment