Download the PHP package ttempleton/craft-nocache without Composer

On this page you can find all versions of the php package ttempleton/craft-nocache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package craft-nocache

No-Cache

A Craft CMS Twig extension that escapes caching inside cache blocks

It also works when disabling the cache from included files:

template.twig:

If you need to reference variables outside of the nocache tag, you will need to pass a context – much like how the include tag works when passing variables. Note that you do not have to pass global variables, such as craft or currentUser, but you will have to import your macros again.

Requirements

No-Cache requires Craft CMS 4.0.0 or later.

Installation

No-Cache can be installed from the Craft Plugin Store or with Composer.

Craft Plugin Store

Open your project's control panel, navigate to the Plugin Store, search for No-Cache and click Install.

Composer

Open your terminal, navigate to your project's root directory and run the following command:

Then open your project's control panel, navigate to Settings → Plugins, find No-Cache and click Install.

Example: User information

Say you have a list of products you want to show on your page. Under each product, you want an "add to cart" button. However, you only want to show this button if a user is logged in. Not only that, but you also want to disable the button if the user already has it in their cart. Unfortunately you're outputting 20 products a page with images, so caching the list seems like the responsible thing to do.

Now we have a problem. The cache around the list of products will cause the currentUser logic to essentially not work, since they'll be cached along with the products. You can't isolate the user logic by separating things into multiple cache blocks, since you're in a loop, and the whole point was to cache the database call that grabs the product entries. So you either have to apply your user checking in Javascript (far from ideal), or disregard caching altogether.

With nocache tags you can fix this very easily:

The nocache block will allow you to cache the entire product list, but still perform your user logic outside of the cache. It also allows passing of context, so you can still refer to products and entries inside the nocache block and access their properties, without any additional database calls.

Example: CSRF tokens

A fantastic security feature, but one that basically renders caching impossible to use. Often you might find yourself outputting a form to the frontend, but it's nested deep within a stack of template includes and macros. At the top of this stack you've conveniently wrapped a cache tag around it.

Well, now your CSRF tokens are going to be cached and there's basically nothing you can do about it. Using nocache tags, this is no longer a problem:

Now you can include this form anywhere in your templates and not have to worry about your CSRF tokens being cached. As a side note, yes nocache tags will work even when they are not inside a cache block (though try and avoid doing this as nocache tags do add some overhead).

Caveat

Content inside nocache blocks will render slightly different than normal. Variables declared outside of the nocache block will actually have their values cached for the duration of the cache block.

This causes an issue in situations like the following:

You would expect that if you were to change the title of the article, it will update inside the nocache block. This is not the case, as the article itself would be cached due to the cache block.

There's a few ways around this. You could move the {% set articles %} statement within the cache block, so updating the article would cause the cache to bust. In situations where you are using the article inside the cache (but outside the nocache block) this is the preferred method, as you won't spend any database calls grabbing the article inside the nocache block.

The other option is to query for the article inside the nocache block. This can be better than the above solution as updating the article title will not bust the cache. The difference in this situation is now the contents of the nocache block will cause a database call.

Every situation will be different, so use your best judgement.


Big thanks to Ben Fleming for creating No-Cache and for letting me take it over.


All versions of craft-nocache with dependencies

PHP Build Version
Package Version
Requires craftcms/cms Version ^4.0.0|^5.0.0-alpha
php Version ^8.0.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ttempleton/craft-nocache contains the following files

Loading the files please wait ....