Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SCODOC_R6A06
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Paul Milleville
SCODOC_R6A06
Commits
0634dbd0
Commit
0634dbd0
authored
1 year ago
by
Emmanuel Viennet
Committed by
Iziram
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Cache: delete_pattern
parent
4d19d385
Branches
master
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/scodoc/sco_cache.py
+27
-0
27 additions, 0 deletions
app/scodoc/sco_cache.py
sco_version.py
+1
-1
1 addition, 1 deletion
sco_version.py
tests/unit/test_caches.py
+4
-0
4 additions, 0 deletions
tests/unit/test_caches.py
with
32 additions
and
1 deletion
app/scodoc/sco_cache.py
+
27
−
0
View file @
0634dbd0
...
@@ -121,6 +121,33 @@ class ScoDocCache:
...
@@ -121,6 +121,33 @@ class ScoDocCache:
for
oid
in
oids
:
for
oid
in
oids
:
cls
.
delete
(
oid
)
cls
.
delete
(
oid
)
@classmethod
def
delete_pattern
(
cls
,
pattern
:
str
,
std_prefix
=
True
)
->
int
:
"""
Delete all keys matching pattern.
The pattern starts with flask_cache_<dept_acronym>.
If std_prefix is true (default), the prefix is added
to the given pattern.
Examples:
'
TABASSI_tableau-etud-1234:*
'
Or, with std_prefix false,
'
flask_cache_RT_TABASSI_tableau-etud-1234:*
'
Returns number of keys deleted.
"""
# see https://stackoverflow.com/questions/36708461/flask-cache-list-keys-based-on-a-pattern
assert
CACHE
.
cache
.
__class__
.
__name__
==
"
RedisCache
"
# Redis specific
import
redis
if
std_prefix
:
pattern
=
"
flask_cache_
"
+
g
.
scodoc_dept
+
"
_
"
+
cls
.
prefix
+
"
_
"
+
pattern
r
=
redis
.
Redis
()
count
=
0
for
key
in
r
.
scan_iter
(
pattern
):
log
(
f
"
{
cls
.
__name__
}
.delete_pattern(
{
key
}
)
"
)
r
.
delete
(
key
)
count
+=
1
return
count
class
EvaluationCache
(
ScoDocCache
):
class
EvaluationCache
(
ScoDocCache
):
"""
Cache for evaluations.
"""
Cache for evaluations.
...
...
This diff is collapsed.
Click to expand it.
sco_version.py
+
1
−
1
View file @
0634dbd0
# -*- mode: python -*-
# -*- mode: python -*-
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
SCOVERSION
=
"
9.6.7
7
"
SCOVERSION
=
"
9.6.7
8
"
SCONAME
=
"
ScoDoc
"
SCONAME
=
"
ScoDoc
"
...
...
This diff is collapsed.
Click to expand it.
tests/unit/test_caches.py
+
4
−
0
View file @
0634dbd0
...
@@ -48,6 +48,10 @@ def test_notes_table(test_client): # XXX A REVOIR POUR TESTER RES TODO
...
@@ -48,6 +48,10 @@ def test_notes_table(test_client): # XXX A REVOIR POUR TESTER RES TODO
formsemestre_id
=
sem
[
"
formsemestre_id
"
]
formsemestre_id
=
sem
[
"
formsemestre_id
"
]
nt
:
NotesTableCompat
=
res_sem
.
load_formsemestre_results
(
formsemestre
)
nt
:
NotesTableCompat
=
res_sem
.
load_formsemestre_results
(
formsemestre
)
assert
sco_cache
.
ResultatsSemestreCache
.
get
(
formsemestre_id
)
assert
sco_cache
.
ResultatsSemestreCache
.
get
(
formsemestre_id
)
# Efface les semestres
sco_cache
.
ResultatsSemestreCache
.
delete_pattern
(
"
*
"
)
for
sem
in
sems
[:
10
]:
assert
sco_cache
.
ResultatsSemestreCache
.
get
(
formsemestre_id
)
is
None
def
test_cache_evaluations
(
test_client
):
def
test_cache_evaluations
(
test_client
):
...
...
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