Updating Cached Front-Facing Content After Gallery Edits: Difference between revisions
(Created page with "== Overview == Documentation of the process of refreshing cached front-facing content after editing gallery images in the Albums CMS. == Use cases == * Add a new image to t...") |
|||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 11: | Line 11: | ||
* Update the Album's cache | * Update the Album's cache | ||
== | == Considerations == | ||
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 == | |||
* 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 == | |||
* 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()`) | |||
** <span style="font-style:italic;color:red">N.B. The logic to update the front-end content cache doesn't exist in this routine currently.</span> | |||
** 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 == | |||
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: | |||
<syntaxhighlight lang="php"> | |||
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(); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
== Examples == | |||
* [http://damienjay.com/hostmgr/comics/|damienjay.com comics and sketchbook CMS] | |||
[[Category:Albums CMS]] | [[Category:Albums CMS]] | ||
[[Category:CMS Documentation]] | [[Category:CMS Documentation]] | ||
[[Category:JQuery/AJAX]] | [[Category:JQuery/AJAX]] | ||
Latest revision as of 17:19, 17 September 2013
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.
[edit]
- Add/edit a page image
/_ajax/images/edit_image.phpcache_class::refresh_content_after_edit()→cache_class::refresh_content_after_image_edit()
- Delete a page image
/_ajax/images/del_image.phpcache_class::refresh_content_after_edit()→cache_class::refresh_content_after_image_edit()
- Fetch gallery listings markup
/_ajax/images/gallery_listings.phpcache_class::retrieve_gallery_listings_content()falling back oncache_class::refresh_content_after_edit()
- Resort page images
/_ajax/utils/resort.phpresort_class(local to site) →resort_base_class(shared)resort_class::save()(after callingresort_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.phpafter the call toresort_class::update_positions()- Include
cache_classif it exists on the local site. - If
cache_classhas methodupdate_frontend_content_cache()- Load the appropriate object (using
cache_class::set_content_and_filters() - Call
cache_class::update_frontend_content_cache()
- Load the appropriate object (using
- Include
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();
}
}
}
}
}