In computation, cache is used to store the state of something that is complex to generate. We then use the cached version for future requests.
Taking a look inside the register_post_type function, I see that it does a lot of stuff:
// ... $post_type_object = new WP_Post_Type( $post_type, $args ); $post_type_object->add_supports(); $post_type_object->add_rewrite_rules(); $post_type_object->register_meta_boxes(); $post_type_object->add_hooks(); $post_type_object->register_taxonomies(); // ...
register_post_type is hooked at init, it runs on every request. If the CPT uses metabox, you'd have
add_meta_boxes running as well, and so on. Depending on the complexity of the CPT, this can get really messy.
I think this is a great candidate for caching. It runs on every request, and it's complex to generate.
That being said, is it possible to cache the creation of the Custom Post Type object in WordPress?
- Without the use of cache plugins or third-party software.
- Caching not only the post, but the metaboxes related to it, etc, for optimal performance at benchmarks, etc.