Cache simple entities

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the caching category.

Last Updated: 2023-12-03

Some caching systems allow you to cache complex objects - e.g. an array of Wistia::Video instances.

This is not advised.

You will get a bug later later if the Wistia::Video class definition has not been loaded (and possibly if the class definition has changed).

Therefore it is wiser to cache simple data types (hashes, arrays, times, strings) rather than data types given by APIs or gems. Then write code to populate the complex classes based on the simple contents.

Aside - The "use simple data" principle is true wherever you have boundaries

e.g. In React Native, you cannot use rich objects as navigation params in React Native navigation

I could not do this:

naviagation.navigate("TruckPhoto", {truck}) // where truck contain dates and nested arrays

React complained that I cannot use non-serializable params

It should be:

naviagation.navigate("TruckPhoto", {truckId}) // just an int