Jump to content

Search the Community

Showing results for tags 'wirecache'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 3 results

  1. I highly recommend reading the second post, too before implementing anything, as it might simplify a lot, depending on your setup.. Because I just updated all MarkupCaches with newer WireCache, couple of weeks ago, and really like it, I thought why not share it. So I got _init.php as prependTemplateFile, and _out.php as appendTemplateFile. But let's check out the interesting part, for example an article.php template. but for some pages, for example blog, it makes sense to include all children ;-) You can include any page you like, or define a time or a template as expiration rule. Here my defaults from the _init.php $cacheNamespace = "hg"; $cacheTitle = "$page->template-" . $sanitizer->pageName($page->getLanguageValue($en, "title")) . "-$page->id-{$user->language->name}"; $cacheTitle .= $pageNum ? "-$pageNum": ''; $cacheExpire = $page; I'm not exactly sure if there is any benefit in using a namespace, you can omit the namespace part and if needed just prefix the cache title. Works both. You'll see why I added the namespace/prefix a little later ;-) For the title I'm getting, the template, english page title (you can of course use the language title and omit the language name part, but I liked it better to have the caches grouped.. After language name I'm adding the page number if present. If you need you can of course create a different, more or less specific cache title. Add get parameters or url segments for example. Then I have $cacheExpire already set to $page as default value, so I don't need to set it in every template So my markup (only the important parts) looks like this: //You can have anything you like or need uncached above this $cacheExpire = $page->chilren(); $cacheExpire->add($page); $cache->getFor($cacheNamespace, $cacheTitle, "id=$cacheExpire", function($pages, $page, $users, $user) use($headline) { // as you can see, within the function() brackets we can pass any Processwire variable we need within our cached output. // If you don't need any you can of course leave the brackets empty // and if you need any other variable wich you had to define outside this function you can pass them via use() // so here goes all your markup you want to have cached // for example huge lists, or whatever }); // Then I have some more uncached parts, a subscription form for example. // After this comes another cached part, which gets -pagination appended to the title. Otherwise it would override the previous one. // It's not only caching the pagination, I just needed a name for differentiation. $cache->getFor($cacheNamespace, $cacheTitle.'-pagination', "id=$cacheExpire", function($pages, $page, $users, $user) use($headline) { // so here comes more cached stuff }); After this your template could end or you can have more uncached and cached parts, just remember to append something to the cache title ;-) Now comes, at least for me, the fun part haha In my prepended _init.php template file I have the following code under the cache vars: if($user->isSuperuser() && $input->get->cache == 'del') { if($input->get->clearAllCaches == "true") { $allCaches = $cache->get("hg__*"); foreach($allCaches as $k => $v) $cache->delete($k); $session->alert .= "<div class='alert alert-success closable expire'>All (".count($allCaches).") caches have been deleted. <i class='fa fa-close'></i></div>"; } else { $currentPageCaches = $cache->get("hg__$page->template-" . $sanitizer->pageName($page->getLanguageValue($en, "title")) . "-$page->id*"); foreach($currentPageCaches as $k => $v) { $cache->delete($k); $session->alert .= "<div class='alert alert-success closable expire'>Cache: $k has been deleted. <i class='fa fa-close'></i></div>"; } } $session->redirect($page->url); } So when I append the parameter "?cache=del" to any URL all cache files within my namespace and beginning with the predefined $cacheTitle will be removed. Means all language variations and the "-pagination & -comments" caches will be deleted, too. This is the else part. But if I append "&clearAllCaches=true", to the first parameter, it will get all caches within my namespace and clear them. Without the namespace it would clear Processwires caches (like the module cache), too. I'm storing a little success message in a session called "alert" which is closable by the FontAwesome icon via jQuery and expires after some seconds, means it will remove itself, so I don't have to click ;-) Maybe it makes more sense to change the cache title and have the page->id first, so you could select all related caches with $cache->get("hg__{$page->id}*"); I liked them grouped by template in the database, but maybe I change my mind soon because of this For not having to type those params manually I have two buttons in my _out.php template file. I have a little, fixed to the left bottom corner admin menu with buttons for backend, edit (current page), and now clear cache button which unveils the clear all caches button on hover, so it's harder to click it by mistake. When someone writes a comment, I added similar lines as above, after saving the comment, to clear comment caches. Ah, the comment caches look like "-pagination" just with "-comments" appended instead. I don't know if there is an easy way to expire a cache when a new children (especially backend created) is created, other than building a little hook module. With MarkupCache it could be a pain to delete all those folders and files in /assets/ folder, especially with slow connection. The database driven WireCache makes it much faster, and easier when set up those few lines of code to make it for you. more about WireCache http://processwire.com/blog/posts/processwire-core-updates-2.5.28/#wirecache-upgrades https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/WireCache.php Hope it helps someone and is okay for Tutorial section, if you have any questions, suggestions or ideas feel free to share. Hasta luego Can
  2. I'm using "quiet" saving in the Webmention module and was wondering if that prevents the page's cache from being cleared. I'm just using the built-in page caching with the option "Clear cache for saved page only (default)" If it matters, the page-save I'm calling is specifying the Webmention Field, rather than just $page->save(); For reference, the code is https://github.com/gRegorLove/ProcessWire-Webmention/blob/master/Webmention/Webmention.module#L840
  3. Hey folks, just got an "Unable to encode array data for cache.." error from WireCache. Had an ´ (acute accent) in a page title, after changing to ' (single quote) everything worked again. I have to say, that the acute accent didn't looked good anyway, got this weird black thing^^ The only thing I tried so far, was changing line 318 of WireCache.php to $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); couldn't recognize any difference.. So am I better off changing those (don't know if there are more..) or what else can I do?
×
×
  • Create New...