Skip to main content

A plugin for Orthanc DICOM server to cache API responses

Project description

Orthanc Cache Plugin

This is a python plugin for Orthanc to enable caching of responses and provide HTTP cache control headers to the REST API

This is still a work in progress. Please use with caution. Contributions are welcome.

Server-side caching

The plugin will cache the responses to GET requests to the REST API. The cache is stored on disk in a directory /var/lib/orthanc/cache.

Cache expiration is in 7 days since the cache was created.

Cache is done using the diskcache library, and the cache size is limited to 1GB, using the LRU eviction policy. Cache is versioned using resource's LastUpdate metadata.

Responses with binary data are not cached on the server-side, for example /instances/{id}/file and /instances/{id}/preview, but the client-side caching will still work.

Client-side caching

The plugin will add HTTP cache control headers to the responses to GET requests.

Date: Mon, 20 Feb 2023 15:00:00 GMT
Last-Modified: Mon, 20 Feb 2023 14:00:00 GMT
ETag: 2e31e40208063db2c9edccf2ec012753
Cache-Control: max-age=604800, s-maxage=604800, public
Expires: Mon, 27 Feb 2023 15:00:00 GMT    

This allows clients to cache the responses and use the cached response for subsequent requests to the same resource when the resource is not modified.

If the client is behind a proxy, the proxy can cache the response and serve it to other clients. CDN's can also cache the response.

Make sure to configure the proxy or CDN to always revalidate the cache with the server before serving the cached response and always forward the http authentication headers to the server, in order to get the correct response.

This plugin will return a 304 Not Modified response if the client has a valid cache.

Server-side cache warmup

The plugin registers with the Orthanc event system and will warm the cache when a new patient or study or series is stable.

At this point, the resource is safe to cache, so when the client requests the resource, it will be served from the cache.

Installation

There are python requirements for the plugin. Here is an example Dockerfile for a docker image with the plugin's requirements.

FROM osimis/orthanc

RUN pip install pytz
RUN pip install diskcache

To enable the plugin, add the following to the script that is configured as the Python startup script in Orthanc. See example.py in the root of this repository.

import sys
sys.path.append('/usr/share/orthanc/plugins/')

from orthanc_cache_plugin import enable_cache_plugin

enable_cache_plugin()

Endpoints that are cached

The following endpoints are cached:

GET patients/{id}/archive
GET patients/{id}/attachments
GET patients/{id}/instances-tags
GET patients/{id}/media
GET patients/{id}/shared-tags

GET studies/{id}/archive
GET studies/{id}/attachments
GET studies/{id}/instances-tags
GET studies/{id}/media
GET studies/{id}/shared-tags

GET series/{id}/archive
GET series/{id}/attachments
GET series/{id}/instances-tags
GET series/{id}/media
GET series/{id}/shared-tags

GET /instances/{id}/file
GET /instances/{id}/frames
GET /instances/{id}/frames/{frame}/*
GET /instances/{id}/metadata
GET /instances/{id}/preview
GET /instances/{id}/raw
GET /instances/{id}/simplified-tags
GET /instances/{id}/tags

Orthanc module API

See documentation at /docs/orthanc-module-api.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

orthanc_cache_plugin-0.0.1.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

orthanc_cache_plugin-0.0.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file orthanc_cache_plugin-0.0.1.tar.gz.

File metadata

  • Download URL: orthanc_cache_plugin-0.0.1.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for orthanc_cache_plugin-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5eb8264b53cda4ab02a9e220b1d7e930a3df64424cfe1877efd62c906806b837
MD5 4796d91fb446fe5ea76bb403fd660cc0
BLAKE2b-256 d390136fbce407091da059445e4854b13d998bee6c391c754eb8f63ea5123e6d

See more details on using hashes here.

File details

Details for the file orthanc_cache_plugin-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for orthanc_cache_plugin-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 27564c58671f50d07d29b50645a654b263cd5d1ab178af001697fad832531e3d
MD5 f8ab9bc84872e065556c12d715ec00d7
BLAKE2b-256 61f3c2dcaba70d33bbf79c76993f1a46b473073469daffa3401648ce527bbf3e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page