Deleting Runtime Caches

Problem

You want to request the removal of a specified runtime cache.

Solution

Call the DELETE /v1/system/caches/runtime endpoint.

You must specify the language, version, and image name for the runtime cache you wish to delete. See Viewing Runtime Caches to view runtime caches on your Connect server.

from posit import connect

LANGUAGE = "Python"
VERSION = "3.7.6"
IMAGE_NAME = "Local"

client = connect.Client()

instructions = {
    "language": LANGUAGE,
    "version": VERSION,
    "image_name": IMAGE_NAME
}

response = client.delete(
    "v1/system/caches/runtime",
    json=instructions,
)

Runtime cache deletion can take some time. A successful request indicates that deletion was started, and returns a task object. You can use this task to poll Connect’s tasks API to check the status of the deletion.

>>> response.json()
{'language': 'Python',
 'version': '3.7.6',
 'image_name': 'Local',
 'task_id': 'lFvijYN16kjCoal6'}

Use Connect’s GET /v1/tasks/{id} endpoint to check the status of a deletion task.

task_id = response.json()["task_id"]
task_status = client.get(f"/v1/tasks/{task_id}")
>>> task_status.json()
{'id': 'lFvijYN16kjCoal6',
 'output': ['Deleting runtime cache...', 'Successfully deleted runtime cache'],
 'result': None,
 'finished': True,
 'code': 0,
 'error': '',
 'last': 2}
Note

This functionality requires connectapi version 0.4.0 or later.

You must specify the language, version, and image name for the runtime cache you wish to delete. See Viewing Runtime Caches to view runtime caches on your Connect server.

library(connectapi)

LANGUAGE <- "R"
VERSION <- "4.3.0"
IMAGE_NAME <- "Local"

client <- connect()

client <- connect()

task <- delete_runtime_cache(
  client,
  language = LANGUAGE,
  version = VERSION,
  image_name = IMAGE_NAME
)

Runtime cache deletion can take some time. A successful request indicates that deletion was started, and returns a task object. You can use the poll_task() function to check the status of the deletion.

> poll_task(task)
Deleting runtime cache...
Successfully deleted runtime cache
Posit Connect Task:
  Task ID: ER6i7P1B664bt4KW