Updating Cached Front-Facing Content After Gallery Edits

From Littledamien Wiki
Jump to navigation Jump to search

Overview[edit]

Documentation of the process of refreshing cached front-facing content after editing gallery images in the Albums CMS.

Use cases[edit]

  • Add a new image to the gallery
  • Edit an existing image in the gallery
  • Delete an existing image in the gallery
  • Click "update cache" button for the gallery
  • Update the Album's cache

Considerations[edit]

The routine that generates the gallery listings markup for the CMS should be separate from the routine that is run after editing operations.

Toggling a gallery, or fetching a gallery on an album's details page should not cause the front-end cache to be updated even though the editing AJAX operations and viewing AJAX operations should share the logic that generates the gallery listings markup.

Operations requiring cache updates[edit]

  • Add a page/image to a gallery.
  • Edit a page/image in a gallery.
  • Delete a page/image in a gallery.
  • Change the order of pages/images in a gallery.

Operations and their shared default handlers[edit]

  • Add/edit a page image
    • /_ajax/images/edit_image.php
    • cache_class::refresh_content_after_edit()cache_class::refresh_content_after_image_edit()
  • Delete a page image
    • /_ajax/images/del_image.php
    • cache_class::refresh_content_after_edit()cache_class::refresh_content_after_image_edit()
  • Fetch gallery listings markup
    • /_ajax/images/gallery_listings.php
    • cache_class::retrieve_gallery_listings_content() falling back on cache_class::refresh_content_after_edit()
  • Resort page images
    • /_ajax/utils/resort.php
    • resort_class (local to site) → resort_base_class (shared)
    • resort_class::save() (after calling resort_class::update_positions())
    • N.B. The logic to update the front-end content cache doesn't exist in this routine currently.
    • The logic to implement updating the front-end content cache should probably be added to /_ajax/utils/resort.php after the call to resort_class::update_positions()
      • Include cache_class if it exists on the local site.
      • If cache_class has method update_frontend_content_cache()
        • Load the appropriate object (using cache_class::set_content_and_filters()
        • Call cache_class::update_frontend_content_cache()

Adding logic to update front-end cached content after page image edits[edit]

The site's local cache_class should have 2 routines defined: refresh_content_after_image_edit($content, $filters, $json) and retrieve_gallery_listings_content($content, $filters, $json).

cache_class::retrieve_gallery_listings_content() simply loads the gallery listings template, populates it with data, and returns the resulting markup.

cache_class::refresh_content_after_image_edit() calls cache_class::retrieve_gallery_listings_content() and then executes the logic to update the front-end cached content.

For example:

public static function refresh_content_after_image_edit ( &$content, &$filters, &$json )
	{
		switch($content->site_section->id->value)
		{
			case comics_class::PAGE_SECTION_ID:
			case sketchbook_class::PAGE_SECTION_ID:
			case stasis_class::PAGE_SECTION_ID:

				cache_class::retrieve_gallery_listings_content($content, $filters, $json);
				cache_class::update_parent_frontend_cache($content, $filters, $json);
				break;
		}
	}

	public static function update_parent_frontend_cache( &$content, &$filters, &$json )
	{
		if ($content instanceof image_link_class)
		{
			if ($content->parent_id->value > 0)
			{
				$parent = null;
				$content_type_id = $content->get_parent_content_type_id();
				if ($content_type_id)
				{
					cache_class::set_content($content_type_id, $parent);
					if (is_object($parent) && method_exists($parent, "update_cache"))
					{
						$parent->id->value = $content->parent_id->value;
						$parent->read(true);
						$json->status->value .= $parent->update_cache();
					}
				}
			}
		}
	}

Examples[edit]