liveBook · Manning

Caching

As explained in Data Pipelines with Apache Airflow, Second Edition

Caching is the technique of storing computed or retrieved objects so later requests can reuse them without repeating the original work.

Caching stores computed, retrieved, or intermediate data so later work can reuse it instead of repeating the original operation. In Airflow workflows, this supports efficient reruns: individual tasks can restart from available outputs rather than recomputing every dependency. section 12.3.3

Cache a hook connection

A custom API hook can cache its authenticated session and base URL in protected instance variables. The first get_conn call reads connection details from the Airflow metastore and creates the session; later calls return the cached objects without repeating that lookup. section 9.2.1

Apply caching to data pipelines with these operational choices:

  • Store intermediate outputs where workers can access them, allowing downstream tasks to rerun independently. section 12.3.3
  • Retain intermediate data for a limited period when storage costs make keeping every large version impractical. section 12.3.3
  • Keep the rawest ingested data available so processing can be repeated after code changes or failures. section 12.3.3
  • If checking for existing outputs, account for cases where intermediate data must be deliberately rewritten. section 12.3.3
Figure 12.11 Storing intermediate data from tasks ensures that we can easily run each task independently. In this case, cloud storage (indicated by the bucket) is used to store intermediate results of the fetch/preprocess tasks.

The workflow diagram shows cloud storage holding intermediate results from fetch and preprocess tasks, making each task independently rerunnable. section 12.3.3

How Data Pipelines with Apache Airflow, Second Edition covers it

How deep it goes
Shows instance-level implementation and pipeline retention trade-offs, but does not specify a general cache invalidation strategy.
Examples
Uses a cached API session and base URL, plus cloud-stored fetch and preprocess outputs.
What it assumes
Assumes familiarity with Airflow tasks and hooks while explaining caching from concrete session and intermediate-data examples.
What you can do after
Apply it via Airflow hooks and shared filesystems to reduce repeated work and rerun selected tasks after failures.
How it connects
Connects caching with Airflow hooks, task reruns, intermediate data, cloud storage, raw data, and data reprocessing.

Also explained in

Compare how 38 books explain caching →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Pipelines with Apache Airflow, Second Edition. The section links point to the parts of the book it draws on.