AZIndex: Caching In — Update

AZIndex LogoJust a quick update for those who are following developments for my AZIndex plugin (is there anybody out there… there… there… ?).

Anyway, it looks like I have a viable caching solution almost completed, and the speed improvements are quite gratifying.  I have created several test indexes containing over 1100 items and the index pages load anywhere from 4x to 50x faster when they are being cached, depending on the options set for the index.

Obviously indexes with multiple pages see the biggest gains because if you put 1000 items on one index page, the plugin still has to loaded all 1000 items from the database even though they don’t have to be sorted.  Even so, a 4x speed improvement is nothing to sniff at.  But if you have a large number of items in the index, it’s only natural to have them spread over multiple pages, so in most cases you will see at least a 10x improvement over a non-cached index.

I have added an option to disable caching, but I recommend against using it unless you think you might be having problems with caching, and you can reset the cache from the admin page if necessary.

How does AZIndex know when the cache is out of date?  Well, it attaches to the WordPress action hooks which fire when someone saves or publishes a post.  Each index maintains a dirty list of posts and pages that have changed since the cache was last rebuilt, and when the index is next display, it checks though its dirty laundry (if you will) to see if the ordering of the items has been affected by the changes, or if a post needs to be removed from or added to the index.  If it does find the index needs to be updated, then it will rebuild the cache causing a one-time slower load for one very slightly unlucky user.

Hooking changes to custom fields turned out to be a pain, since there are no definitive hooks for them, and you can change them without having to save the post afterwards.  In the end I attach to the Ajax hooks which fire when a user is editing a custom field.  That will probably work for 99% of all custom field changes, but if a blog uses another plugin to change custom fields using the function calls, then there is little AZIndex can do to detected those changes.  But in the worst case, all the blogger has to do is manually clear the cache once all the changes have been made.

So, be on the lookout for AZIndex v0.5 with full caching support sometime this week, just in time for the holiday weekend.

5 thoughts on “AZIndex: Caching In — Update

  1. Gregg Hawkins

    I was wondering if there’s an option to exclude certain pages from showing up in the index? I want to create pages for artists and have the artist names only show up, however the navigation pages I created are showing in the index as well.

    Also, how do I get rid of the bullets? Thanks!

    Reply
  2. English Mike Post author

    Hi Gregg,

    Thanks for your questions. In finding the answers, I actually learned something about CSS today!

    So, taking the bullet question first, the answer is that you’ll have to modify your theme’s stylesheet and customize the AZIndex CSS, but it’s not difficult. The problem is that you have the following entry in your theme’s stylesheet:

    #content .post ul li {
       list-style-type: disc !important;
    }

    What I didn’t know about CSS was that if you stick “!important” on the end of a line, the style will be used even if you try to override it later (which is what AZIndex tries to do, but fails). So the first thing to do is remove “!important” from that line so that it now looks like:

    #content .post ul li {
       list-style-type: disc;
    }

    Note: if you will never need bullets in your lists in your blog’s contents then you can remove the whole line and you will have fixed the problem, but if you want to keep bullets in your other lists, then follow the rest of the instructions here.

    BTW: To edit the theme by going to Design >> Theme Editor and edit the theme’s stylesheet (usually called stylesheet.css or styles.css). I don’t think that removing the !important tag will affect the appearance of rest of your blog.

    Now if you check your index, you will still probably see the “disc” markers on your items (in FireFox anyway). I tried a number of different CSS tweaks to the index’s CSS, but only one of them seems to work. Edit the index settings and select the Use customized stylesheets for the index option. Now scroll down to the stylesheet (make sure you select the correct one for the type of index you have — or just make the same change in both) and add the following line to the CSS:

      #content .post .azindex ul li {list-style:none}

    (Important: Do not remove any of the other lines!)

    That should turn off those pesky bullets. I’ll continue to look out for a way to set up the default index to not have bullets even if the theme sets them for all lists, but I’m not sure I will be able to come up with one. (Sounds like a good topic for an FAQ though!).

    I will post another comment shortly on your other question.

    Reply
  3. English Mike Post author

    Now, regarding leaving pages out of the index. Though there is no magic option, there are a couple of ways to do this:

    1. You can define your index headings to be a “Custom Field” (in the index settings) — say “Artist” — and then set the name of the artist as you want them to appear in the index in a custom field on each of the pages you want in the index. AZIndex will filter out all the pages that do not have a custom field of “Artist” set, so the other non-artist pages will be omitted from the index. Using a custom field might be a little bit of a pain, but if you want to use last names to sort (e.g. Amos, Tori) then they are a good way to do that without messing with the title of the page (e.g. that can still be “Tori Amos”). (Note: there is a bug in v0.4 of AZIndex which means that the pages may not get filtered properly (you will see blank entries instead, but I have already fixed it and the fix will be in the next version).
    2. The other way to do it would be to “tag” your pages (like you can “tag” posts), but there’s one snag — WordPress in its wisdom doesn’t let you do that easily though under the covers there is no reason why you should not be able to. However, there is a plugin that adds support for adding tags to pages: tags4page. I just tried it quickly, and it seems to work great with AZIndex. Just edit the index settings and add the tag name of your choice to the “Included Tags” field then you can add that tag to all the pages you want in the index.

    One of those should solve your problem. The second one (tagging the pages you want) is probably the better option, unless you want to have fine control over how the names appear in the index. There is also no reason why you can’t do both at the same time.

    Let me know if you have any other questions.

    Mike

    Reply
  4. Carolyn

    A very nice plugin – easy to install and set up (and I’m a new WordPress user) I’ll be installing it on both my WP blogs. Thanks!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *