Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
We all need values in our applications. That is why we interact with the request context in order to place data from our model layer into it so our views can display it, or to retrieve data from a user's request. You will either interact with the event object to get/set values or put/read values directly via the received rc
and prc
references.
We would recommend you use the private request collection (prc
) for setting manual data and using the standard request collection (rc
) for reading the user's unsafe request variables. This way a clear distinction can be made on what was sent from the user and what was set by your code.
Important The most important paradigm shift from procedural to an MVC framework is that you NO LONGER will be talking to URL, FORM, REQUEST or any ColdFusion scope from within your handlers, layouts, and views. The request collection already has URL, FORM, and REQUEST scope capabilities, so leverage it.
The framework provides you with the relocate()
method that you can use to relocate to other events thanks to the framework super type object, the grand daddy of all things ColdBox.
Please see the Super Type CFC Docs for further investigation of all the goodness of methods you have available.
It is extremely important that you use this method when relocating instead of the native ColdFusion methods as it allows you to gracefully relocate to other events or external URIs. By graceful, we mean it does a lot more behind the scenes like making sure the flash scope is persisted, logging, post processing interceptions can occur and safe relocations.
So always remember that you relocate via relocate()
and if I asked you: "Where in the world does event handlers get this method from?", you need to answer: "From the super typed inheritance".
The event
object is the object that will let you set the views that you want to render, so please explore its API in the CFC Docs. To quickly set a view to render, do the following:
The view name is the name of the template in the views directory without appending the .cfm. If the view is inside another directory, you would do this:
The views you set will use the default layout defined in your configuration file which by default is the layouts/Main.cfm
We recommend that you set your views following the naming convention of your event. If your event is users.index, your view should be users/index. This will go a long way with maintainability and consistency and also will activate implicit views where you don't even have to use the set view method call.
You can also use the setView(), setLayout()
methods to tell the framework which view and layout combination to use:
You can also tell the framework to set a view for rendering by itself with no layout using the noLayout
argument
Here are the arguments for the setView()
method:
You can leverage the caching arguments in the setView()
method in order to render and cache the output of the views once the framework renders it. These cached views will be stored in the template cache region, which you can retrieve or purge by talking to it: getCache( 'template' )
.
Data can be passed from your handler to the view via rc or prc. If you want to pass data to a view without polluting rc and prc, you can pass it directly via the args parameter, much like a method call.
Access the data in the view like so:
If you don't want to, you don't have to. The framework gives you a method in the event object that you can use if this specific request should just terminate gracefully and not render anything at all. All you need to do is use the event object to call on the noRender()
method and it will present to the user a lovely white page of death.
Handler actions can return data back to its callers in many different formats. Either to create RESTFul services, or just send data that's not HTML back to the user. The different usages can be:
Complex Data
HTML
Rendered Data via event.renderData()
The last option on the list is to support native REST Applications in ColdBox by leveraging the REST Handler.
By default, any complex data returned from handler actions will automatically be marshaled to JSON:
Simple as that. ColdBox detects the complex object and tries to convert it to JSON for you automatically.
renderdata
Action AnnotationIf you want ColdBox to marshall the content to another type like XML or PDF. Then you can use the renderdata
annotation on the action itself. The renderdata
annotation can be any of the following values:
json
jsonp
jsont
xml
html
text
renderdata
Component AnnotationYou can also add the renderData annotation to the component definition and this will override the default of JSON. So if you want XML as the default, you can do this:
If the returned complex data is an object and it contains a function called $renderData(),
then ColdBox will call it for you automatically. So instead of marshaling to JSON automatically, your object decides how to marshal itself.
By default if your handlers return simple values, then they will be treated as returning HTML.
Using the renderdata()
method of the event object is the most flexible for RESTFul web services or pure data marshaling. Out of the box ColdBox can marshall data (structs, queries, arrays, complex or even ORM entities) into the following output formats:
XML
JSON
JSONP
JSONT
HTML
TEXT
WDDX
CUSTOM
Here is the method signature:
Below are a few simple examples:
As you can see, it is very easy to render data back to the browser or caller. You can even choose plain and send HTML back if you wanted to.
You can also render out PDFs from ColdBox using the render data method. The data argument can be either the full binary of the PDF or simple values to be rendered out as a PDF; like views, layouts, strings, etc.
There is also a pdfArgs
argument in the render data method that can take in a structure of name-value pairs that will be used in the cfdocument
(See docs) tag when generating the PDF. This is a great way to pass in arguments to really control the way PDF's are generated uniformly.
The renderData()
method also has two powerful arguments: formats & formatsView
. If you currently have code like this:
Where you need to param the incoming format extension, then do a switch and do some code for marshalling data into several formats. Well, no more, you can use our formats argument and ColdBox will marshall and code all that nasty stuff for you:
That's it! ColdBox will figure out how to deal with all the passed in formats for you that renderdata
can use. By convention it will use the name of the incoming event as the view that will be rendered for HTML and PDF; implicit views. If the event was users.list, then the view would be views/users/list.cfm. However, you can tell us which view you like if it is named different:
If you need to redirect for html events, you can pass any arguments you normally would pass to setNextEvent
to formatsRedirect
.
You can do custom data conversion by convention when marshalling CFCs. If you pass in a CFC as the data
argument and that CFC has a method called $renderdata()
, then the marshalling utility will call that function for you instead of using the internal marshalling utilities. You can pass in the custom content type for encoding as well:
The CFC converter:
In this approach your $renderdata()
function can be much more customizable than our internal serializers. Just remember to use the right contentType argument so the browser knows what to do with it.
Event handlers are ColdBox's version of controllers in the MVC design pattern. So every time you hear "event handler", you are talking about a controller that can listen to external events or internal events in ColdBox. Event handlers are responsible for controlling your application flow, calling business logic, preparing a display to a user and much more.
All your handlers will be stored in the handlers folder of your application template. If you get to the point where your application needs even more decoupling and separation, please consider building ColdBox Modules instead.
Tip: You can create packages or sub-folders inside of the handlers directory. This is encouraged on large applications so you can organize or package handlers logically to facilitate better maintenance and URL experience.
You can also declare a HandlersExternalLocation
directive in your Configuration CFC. This will be a dot notation path or instantiation path where more external event handlers can be found.
If an external event handler has the same name as an internal conventions event, the internal conventions event will take precedence.
By default, ColdBox will only scan for event handlers on startup. For development we highly encourage you leverage the following configuration directives:
Event handlers are CFCs that will respond to FORM posts, HTTP requests and/or remote requests (like Flex,Air, SOAP, REST) via an incoming RC variable called event or by URL mappings (Which we saw in the previous section).
You can also remove the inheritance from the CFC and WireBox will extend the coldbox.system.EventHandler
for you using Virtual Inheritance.
Event Handlers are treated as singletons by ColdBox, so make sure you make them thread-safe and properly scoped. Persistence is controlled by the coldbox.handlerCaching
directive
They are composed of functions which are called actions that will always have the following signature:
Each action receives three arguments:
event
- An object that models and is used to work with the current request (otherwise known as the Request Context)
rc
- A struct that contains both URL/FORM
variables (unsafe data)
prc
- A secondary struct that is private. This structure is only accessible from within your application (safe data)
An action will usually do one of the following:
Set a view/layout to render
Return HTML
Return Complex Data which is converted to JSON by default
Relocate to another event/URL Route
The default action for all event handlers is called index()
. This means that when you execute an event, you can omit the index if you so desire.
So what about private
functions? Private functions are not executable from the outside world, but can be executed internally via a function available to all handlers called runEvent()
, which we will explore later.
It is important to note that there is a pre-defined object model behind every event handler controller that will enable you to do your work more efficiently. The following are the automatically generated properties every event handler makes available in their variables
scope:)
cachebox : A reference to the CacheBox library (coldbox.system.cache.CacheFactory
)
controller : A reference to the Application Controller (coldbox.system.web.Controller
)
flash: A flash memory object (coldbox.system.web.flash.AbstractFlashScope
)
logbox: A reference to the application LogBox (coldbox.system.logging.LogBox
)
log: A pre-configured logging logger object (coldbox.system.logging.Logger
)
wirebox : A reference to the application WireBox Injector (coldbox.system.ioc.Injector
)
$super: A reference to the virtual super class if using non-inheritance approach.
Events are determined via a special variable that can be sent in via the FORM, URL, or REMOTELY called event
. If no event is detected as an incoming variable, the framework will look in the configuration directives for the DefaultEvent
and use that instead. If you did not set a DefaultEvent
setting then the framework will use the following convention for you: main.index
Hint : You can even change the event
variable name by updating the EventName
setting in your coldbox
configuration directive.
Please note that ColdBox supports both normal variable routing and URL mapping routing, usually referred to as pretty URLs.
In order to call them you will use the following event syntax notation format:
no event : Default event by convention is main.index
event={handler} : Default action method by convention is index()
event={handler}.{action} : Explicit handler + action method
event={package}.{handler}.{action} : Packaged notation
event={module}:{package}.{handler}.{action} : Module Notation (See ColdBox Modules)
This looks very similar to a Java or CFC method call, example: String.getLength(),
but without the parentheses. Once the event variable is set and detected by the framework, the framework will tokenize the event string to retrieve the CFC and action call to validate it against the internal registry of registered events. It then continues to instantiate the event handler CFC or retrieve it from cache, finally executing the event handler's action method.
Examples
We all need to deliver files to users at one point in time. ColdBox makes it easy to deliver any type of file even binary files via the (event) sendFile()
method.
The API Docs can help you see the entire format of the method:
The method signature is as follows:
Please note that the file
argument can be an absolute path or an actual binary file to stream out.
There are several simple implicit (Aspect Oriented Programming) interceptor methods, usually referred to as advices, that can be declared in your event handler that the framework will use in order to execute them before/after and around an event as its fired from the current handler.
This is great for intercepting calls, pre/post processing, localized security, logging, RESTful conventions, and much more. Yes, you got that right, just for you and without all the complicated setup involved! If you declared them, the framework will execute them.
With this interceptor you can intercept local event actions and execute things before the requested action executes. You can do it globally by using the preHandler()
method or targeted to a specific action pre{actionName}()
.
The arguments received by these interceptors are:
event
: The request context reference
action
: The action name that was intercepted
eventArguments
: The struct of extra arguments sent to an action if executed via runEvent()
rc
: The RC reference
prc
: The PRC Reference
Here are a few options for altering the default event execution:
Use event.overrideEvent('myHandler.myAction')
to execute a different event than the default.
Use event.noExecution()
to halt execution of the current event. ONLY works when executed by interceptions before the main event. It will never work in pre/post advices.
You can fine tune these interception methods by leveraging two public properties in the handler:
this.prehandler_only
: A list of actions that preHandler()
will ONLY fire on
this.prehandler_except
: A list of actions that preHandler()
will NOT fire on
With this interceptor you can intercept local event actions and execute things after the requested action executes. You can do it globally by using the postHandler()
method or targeted to a specific action post{actionName}()
.
The arguments received by these interceptors are:
event
: The request context reference
action
: The action name that was intercepted
eventArguments
: The struct of extra arguments sent to an action if executed via runEvent()
rc
: The RC reference
prc
: The PRC Reference
You can fine tune these interception methods by leveraging two public properties in the handler:
this.posthandler_only
: A list of actions that the postHandler()
action will fire ONLY!
this.posthandler_except
: A list of actions that the postHandler()
action will NOT fire on
Around advices are the most powerful of all as you completely hijack the requested action with your own action that looks, smells and feels exactly as the requested action. This is usually referred to as a
This will allow you to run both before and after advices but also surround the method call with whatever logic you want like transactions
, try/catch
blocks, locks
or even decide to NOT execute the action at all.
You can do it globally by using the aroundHandler()
method or targeted to a specific action around{actionName}()
.
Examples
The arguments received by these interceptors are:
event
: The request context reference
targetAction
: The function pointer to the action that got the around interception. It will be your job to execute it (Look at samples)
eventArguments
: The struct of extra arguments sent to an action if any
rc
: The RC reference
prc
: The PRC Reference
You can fine tune these interception methods by leveraging two public properties in the handler:
this.aroundhandler_only
: A list of actions that the aroundHandler()
action will fire ONLY!
this.aroundhandler_except
: A list of actions that the aroundHandler()
action will NOT fire on
We have a complete section dedicated to the , but we wanted to review a little here since event handlers need to talk to the model layer all the time. By default, you can interact with your models from your event handlers in two ways:
Dependency Injection ()
Request, use and discard model objects ()
ColdBox offers its own dependency injection framework, , which allows you, by convention, to talk to your model objects. However, ColdBox also allows you to connect to third-party dependency injection frameworks via the IOC module:
Aggregation differs from ordinary composition in that it does not imply ownership. In composition, when the owning object is destroyed, so are the contained objects. - wikipedia
Here is the event handler code to leverage the injection:
Notice that we define a cfproperty
with a name and inject
attribute. The name
becomes the name of the variable in the variables
scope and the inject
annotation tells WireBox what to retrieve. By default it retrieves model objects by name and path.
Association defines a relationship between classes of objects that allows one object instance to cause another to perform an action on its behalf. - 'wikipedia'
In this practical example we will see how to integrate with our model layer via WireBox, injections, and also requesting the objects. Let's say that we have a service object we have built called FunkyService.cfc
and by convention we will place it in our applications models
folder.
FunkyService.cfc
Our funky service is not that funky after all, but it is simple. How do we interact with it? Let's build a Funky event handler and work with it.
By convention, I can create a property and annotate it with an inject
attribute. ColdBox will look for that model object by the given name in the models
folder, create it, persist it, wire it, and return it. If you execute it, you will get something like this:
Great! Just like that we can interact with our model layer without worrying about creating the objects, persisting them, and even wiring them. Those are all the benefits that dependency injection and model integration bring to the table.
You can use the value of the inject
annotation in several ways. Below is our recommendation.
Let's look at the requesting approach. We can either use the following approaches:
Via Facade Method
Directly via WireBox:
Both approaches do exactly the same thing. In reality getInstance()
does a wirebox.getInstance()
callback (Uncle Bob), but it is a facade method that is easier to remember. If you run this, you will also see that it works and everything is fine and dandy. However, the biggest difference between injection and usage can be seen with some practical math:
As you can see, the best performance is due to injection as the handler object was wired and ready to roll, while the requested approach needed the dependency to be requested. Again, there are cases where you need to request objects such as transient or volatile stored objects.
See the documentation for more details.
Your event handlers can be autowired with dependencies from by convention. By autowiring dependencies into event handlers, they will become part of the life span of the event handlers (singletons), since their references will be injected into the handler's variables
scope. This is a huge performance benefit since event handlers are wired with all necessary dependencies upon creation instead of requesting dependencies (usage) at runtime. We encourage you to use injection whenever possible.
Warning As a rule of thumb, inject only singletons into singletons. If not you can create unnecessary issues and memory leaks.
You will achieve this in your handlers via property
injection, which is the concept of defining properties in the component with a special annotation called inject
, which tells WireBox what reference to retrieve via the . Let's say we have a users handler that needs to talk to a model called UserService. Here is the directory layout so we can see the conventions
Tip: The is vast and elegant. Please refer to it. Also note that you can create object aliases and references in your : config/WireBox.cfc
The other approach to integrating with model objects is to request and use them as via the framework super type method: getInstance()
, which in turn delegates to WireBox's getInstance()
method. We would recommend requesting objects if they are transient (have state) objects or stored in some other volatile storage scope (session, request, application, cache, etc). Retrieving of objects is okay, but if you will be dealing with mostly singleton objects or objects that are created only once, you will gain much more performance by using injection.
A part from using runEvent()
to execute events, you can also abstract it by using the runRoute()
method. This method is fairly similar but with the added benefit of executing a NAMED route instead of the direct event it represents. This gives you the added flexibility of abstracting the direct event and leveraging the named route.
All the same feature of runEvent()
apply to runRoute()
Just like you can create links based on named routes and params, you can execute named routes and params as well internally via runRoute()
The params argument you pass to the runRoute() method will be translated into event arguments. Therefore they will be passed as arguments to the event the route represents:
In the example above, the userData
named route points to the user.data
event.
If you want to execute module routes, no problem! Just use our @ or :
notation to tell the controller from which module's router we should pick the route from.
More often you will find that certain web operations need to be restricted in terms of what HTTP verb is used to access a resource. For example, you do not want form submissions to be done via GET but via POST or PUT operations. HTTP Verb recognition is also essential when building strong RESTFul APIs when security is needed as well.
You can do this manually, but why do the extra coding :)
This solution is great and works, but it is not THAT great. We can do better.
Another feature property on an event handler is called this.allowedMethods
. It is a declarative structure that you can use to determine what the allowed HTTP methods are for any action on the event handler.
If the request action HTTP method is not found in the approved list, it will look for a onInvalidHTTPMethod()
on the handler and call it if found. Otherwise ColdBox throws a 405 exception that is uniform across requests.
You can listen for global invalid HTTP methods using the coldbox.onInvalidHTTPMethodHandler
located in your config/ColdBox.cfc.
If the action is not listed in the structure, then it means that we allow all HTTP methods. Just remember to either use the onError()
or onInvalidHTTPMethod()
method conventions or an exception handler to deal with the security exceptions.
You can tag your event actions with a allowedMethods
annotation and add a list of the allowed HTTP verbs as well. This gives you a nice directed ability right at the function level instead of a property. It is also useful when leveraging DocBox documentation as it will show up in the API Docs that are generated.
Every event handler controller has some implicit methods that if you create them, they come alive. Just like the implicit methods in Application.cfc
With this convention you can create virtual events that do not even need to be created or exist in a handler. Every time an event requests an action from an event handler and that action does not exist in the handler, the framework will check if an onMissingAction()
method has been declared. If it has, it will execute it. This is very similar to ColdFusion's onMissingMethod()
but on an event-driven framework.
This event has an extra argument: missingAction which is the missing action that was requested. You can then do any kind of logic against this missing action and decide to do internal processing, error handling or anything you like. The power of this convention method is extraordinary, you have tons of possibilities as you can create virtual events on specific event handlers.
This is a localized error handler for your event handler. If any type of runtime error occurs in an event handler and this method exists, then the framework will call your method so you can process the error first. If the method does not exist, then normal error procedures ensue.
Please note that compile time errors will not fire this method, only runtime exceptions.
This method will be called for you if a request is trying to execute an action in your handler without the proper approved HTTP Verb. It will then be your job to determine what to do next:
Apart from executing events from the URL/FORM or Remote interfaces, you can also execute events internally, either public or private from within your event handlers or from interceptors, other handlers, layouts or views.
You do this by using the runEvent()
method which is inherited from our FrameworkSuperType
class. Here is the method signature:
The interesting aspect of internal executions is that all the same rules apply, so your handlers can return content like widgets, views, or even data. Also, the eventArguments enables you to pass arguments to the method just like method calls:
As you can see from the function signature you can tell ColdBox to cache the result of the event call. All of the cached content will go into the template cache by default unless you use the cacheProvider
argument. The cache keys are also based on the name of the event and the signature of the eventArguments
structure. Meaning, the framework can cache multiple permutations of the same event call as long as the eventArguments
are different.
Tip: You can disable event caching by using the coldbox.eventCaching
directive in your config/ColdBox.cfc
The framework also offers you the capability to bind incoming FORM/URL/REMOTE/XML/JSON/Structure data into your model objects by convention. This is done via WireBox's object population capabilities. The easiest approach is to use our populateModel()
function which will populate the object from many incoming sources:
request collection RC
Structure
json
xml
query
This will try to match incoming variable names to setters or properties in your domain objects and then populate them for you. It can even do ORM entities with ALL of their respective relationships. Here is a snapshot of the method:
Let's do a quick example:
Person.cfc
editor.cfm
Event Handler -> person.cfc
In the dump you will see that the name
and email
properties have been bound.
A viewlet is a self sufficient view or a widget that can live on its own, its data is pre-fetched and can just be renderer anywhere in your system.
What in the world is this? Well, imagine a portal, in which each section of the portal is self-sufficient, with controls and data. You don't want to call all the handlers for this data for every single piece of content. It's not efficient, you need to create a separation. Well, a viewlet is such a separation that provides you with the ability to create reusable events. So how do we achieve this?
You will use the method runEvent()
anywhere you want a viewlet to be displayed or the content rendered. This calls an internal event that will be in charge to prepare and render the viewlet.
Create the portable event but make sure it returns the produced content.
This code just renders out the results of a runEvent()
method call. Please note that you can pass in arguments to the event using the eventArguments
argument. This makes the event act like a method call with arguments to it. Remember that all events you call via runEvent()
will share the same RC/PRC.
I would suggest you look at the API docs to discover all arguments to the runEvent()
method call.
As you can see from the code above, the handler signature can accept arguments which are passed via the eventArguments
structure. It talks to a service layer and place some data on the private request collection the viewlet will use. It then returns the results of a renderView()
call that will render out the exact viewlet I want. You can be more creative and do things like:
render a layout + view combo
render data
return your own custom strings
etc
Caution We would suggest you namespace or prefix your private request collection variables for viewlets in order to avoid collisions from multiple viewlet events in the same execution thread or instead pass the necessary arguments into a view via the args
argument.
The view is a normal standard view, it doesn't even know it is a viewlet, remember, views are DUMB!
A content variable is a variable that contains HTML/XML or any kind of visual content that can easily be rendered anywhere. So instead of running the viewlet event in the view, you can abstract it to the controller layer and assign the output to a content variable:
So how do I render it?
Another example, is what if we do not know if the content variable will actually exist? How can we do this? Well, we use the event object for this and its magic getValue() method.
So now, if no content variable exists, an empty string will be rendered.
Important String manipulation in Java relies on immutable structures, so performance penalties might ensue. If you will be doing a lot of string manipulation, concatenation or rendering, try to leverage native java objects: StringBuilder or StringBuffer
Interceptor Method | Description |
| Executes before any requested action (In the same handler CFC) |
| Executes before the |
| Executes after any requested action (In the same handler CFC) |
| Executes after the |
| Executes around any request action (In the same handler CFC) |
| Executes around the |
ColdBox Core MVC does not have validation built-in but it is implemented via the official core cbValidation
module. You can easily install the module in your application via:
You can find much more information about this module in the following resources:
Source:
Documentation:
ForgeBox :
Event caching is extremely useful and easy to use. ColdBox will act like a cache proxy between your events and the clients requesting the events, much like squid, nginx or HA Proxy. All you need to do is add several metadata arguments to the action methods and the framework will cache the output of the event in the template cache provider in CacheBox. In other words, the event executes and produces output that the framework then caches. Subsequent calls to the same event with the same incoming RC variables will not do any processing, but just output the content back to the user.
For example, you have an event called blog.showEntry
. This event executes, gets an entry from the database and sets a view to be rendered. The framework then renders the view and if event caching is turned on for this event, the framework will cache the HTML produced. So the next incoming show entry event will just spit out the cached HTML. The cache key is created by hashing the incoming request collection.
Important to note also, that any combination of URL/FORM parameters on an event will produce a unique cacheable key. So event=blog.showEntry&id=1
& event=blog.showEntry&id=2
are two different cacheable events.
To enable event caching, you will need to set a setting in your ColdBox.cfc
called coldbox.eventcaching
to true
.
Important Enabling event caching does not mean that ALL events will be cached. It just means that you enable this feature.
The way to set up an event for caching is on the function declaration with the following annotations:
Important Please be aware that you should not cache output with 0 timeouts (forever). Always use a timeout.
Alert: DO NOT cache events as unlimited timeouts. Also, all events can have an unlimited amount of permutations, so make sure they expire and you purge them constantly. Every event + URL/FORM variable combination will produce a new cacheable entry.
We also have a great way to purge these events programmatically via our cache provider interface.
Methods for event purging:
clearEvent( string eventSnippet, string querystring="" )
: Clears all the event permutations from the cache according to snippet and querystring. Be careful when using incomplete event name with query strings as partial event names are not guaranteed to match with query string permutations
clearEventMulti( eventsnippets,string querystring="" )
: Clears all the event permutations from the cache according to the list of snippets and querystrings. Be careful when using incomplete event name with query strings as partial event names are not guaranteed to match with query string permutations
clearAllEvents( [boolean async=true] )
: Can clear ALL cached events in one shot and can be run asynchronously.
You can now leverage the cache suffix property in handlers to be declared as a closure so it can be evaluated at runtime so it can add dynamic suffixes to cache keys. This can allow you to incorporate elements into the cache key at runtime instead of statically. This is a great way to incorporate the user's language locale or session identifier to make unique entries.
OnRequestCapture
- Influence Cache KeysWe have provided an interception point in ColdBox that allows you to add variables into the request collection before a snapshot is made so you can influence the cache key of a cacheable event. What this means is that you can use it to mix in variables into the request collection that can make this event cache unique for a user, a specific language, country, etc. This is a great way to leverage event caching on multi-lingual or session based sites.
With the simple example above, the user's locale will be added to all your event caching permutations and thus create entries for different languages.
Several event interception points are NOT available during event caching.
When using event caching the framework will NOT execute ANY event at all. It will stream the content directly from the selected cache provider. This means that any interceptors or code that executes in the event is also NOT executed. The only interception points that will execute are:
preProcess
postProcess
So please make sure you take note of this when planning for event security.
All event and view caching are stored in a named cache called template
which all ColdBox applications have by default. You can open or create a new configuration object and decide where the storage is, timeouts, providers, etc. You have complete control of how event and view caching is stored.
has an intuitive and powerful monitor that can be used via the ColdBox Debugger Module. From the monitor you can purge, expire and view cache elements, etc.
Annotation | Type | Description |
| boolean | A true or false will let the framework know whether to cache this event or not. The default is FALSE. So setting to false makes no sense |
| numeric | The timeout of the event's output in minutes. This is an optional attribute and if it is not used, the framework defaults to the default object timeout in the cache settings. You can place a 0 in order to tell the framework to cache the event's output for the entire application timeout controlled by coldfusion, NOT GOOD. Always set a decent timeout for content. |
| numeric | The last access timeout of the event's output in minutes. This is an optional attribute and if it is not used, the framework defaults to the default last access object timeout in the cache settings. This tells the framework that if the object has not been accessed in X amount of minutes, then purge it. |
| string | The cache provider to store the results in. By default it uses the template cache. |