(
api.macros/defendpoint
:post
"/invalidate"
"Invalidate cache entries.
Use it like `/api/cache/invalidate?database=1&dashboard=15` (any number of database/dashboard/question can be
supplied).
`&include=overrides` controls whenever you want to invalidate cache for a specific cache configuration without
touching all nested configurations, or you want your invalidation to trickle down to every card."
[
_route-params
{
:keys
[
include
database
dashboard
question
]
}
:-
[
:map
[
:include
{
:optional
true
}
[
:maybe
{
:description
"All cache configuration overrides should invalidate cache too"
}
[
:=
:overrides
]
]
]
[
:database
{
:optional
true
}
[
:maybe
{
:description
"A list of database ids"
}
(
ms/QueryVectorOf
ms/IntGreaterThanOrEqualToZero
)
]
]
[
:dashboard
{
:optional
true
}
[
:maybe
{
:description
"A list of dashboard ids"
}
(
ms/QueryVectorOf
ms/IntGreaterThanOrEqualToZero
)
]
]
[
:question
{
:optional
true
}
[
:maybe
{
:description
"A list of question ids"
}
(
ms/QueryVectorOf
ms/IntGreaterThanOrEqualToZero
)
]
]
]
]
(
when-not
(
premium-features/enable-cache-granular-controls?
)
(
throw
(
premium-features/ee-feature-error
(
tru
"Granular Caching"
)
)
)
)
(
doseq
[
db-id
database
]
(
api/write-check
:model/Database
db-id
)
)
(
doseq
[
dashboard-id
dashboard
]
(
api/write-check
:model/Dashboard
dashboard-id
)
)
(
doseq
[
question-id
question
]
(
api/write-check
:model/Card
question-id
)
)
(
let
[
cnt
(
cache-config/invalidate!
{
:databases
database
:dashboards
dashboard
:questions
question
:with-overrides?
(
=
include
:overrides
)
}
)
]
{
:status
(
if
(
=
cnt
-1
)
404
200
)
:body
{
:count
cnt
:message
(
case
[
(
=
include
:overrides
)
(
if
(
pos?
cnt
)
1
cnt
)
]
[
true
-1
]
(
tru
"Could not find any questions for the criteria you specified."
)
[
true
0
]
(
tru
"No cached results to clear."
)
[
true
1
]
(
trun
"Cleared a cached result."
"Cleared {0} cached results."
cnt
)
[
false
-1
]
(
tru
"Nothing to invalidate."
)
[
false
0
]
(
tru
"No cache configuration to invalidate."
)
[
false
1
]
(
trun
"Invalidated cache configuration."
"Invalidated {0} cache configurations."
cnt
)
)
}
}
)
)