Skip to content

Commit 4c9c052

Browse files
committed
improve recipes
1 parent 6dab5c9 commit 4c9c052

11 files changed

+146
-246
lines changed

docs/recipes/caches-defined-in-application-cfc.md

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,7 @@
2424

2525
# Caches defined in Application.cfc
2626

27-
It is possible to add cache connections in Lucee 5.1+ on a per-application basis by adding configuration to your `Application.cfc`.
28-
29-
You can also select the default object cache, query cache, function cache, etc.
30-
31-
Note if these caches use an extension that provides the cache driver, the extension must be installed already.
32-
33-
To declare cache connections, create a struct called `this.cache.connections` in the pseudo constructor of your `Application.cfc`.
34-
35-
Each key in the struct will be the name of the cache connection to create, and the value of the item will be another struct defining the properties of that cache connection.
27+
Add per-application cache connections in `Application.cfc` (Lucee 5.1+). If using an extension-provided cache driver, the extension must be installed first.
3628

3729
```lucee
3830
this.cache.connections["myCache"] = {
@@ -49,33 +41,28 @@ this.cache.connections["myCache"] = {
4941
};
5042
```
5143

52-
Note, there is a shortcut for `this.cache.connections["myCache"] = {}` and that is `this.cache["myCache"] = {}`.
53-
54-
Lucee supports both since the latter is closer to how datasources are defined.
44+
Shortcut: `this.cache["myCache"] = {}` (matches datasource syntax).
5545

5646
## Generating Cache Connection code
5747

58-
The easiest way to generate the code block above is to follow these steps:
48+
Generate the code via Lucee Admin:
5949

60-
1. Start up a Lucee server
61-
2. Create the cache you want via the web admin
62-
3. Edit the cache and scroll to the bottom
63-
4. Copy the code snippet that appears directly into your `Application.cfc`
50+
- Create the cache in Web Admin
51+
- Edit the cache, scroll to bottom
52+
- Copy the code snippet into `Application.cfc`
6453

6554
## Cache metadata
6655

67-
Let's take a look at some of the keys used to define a cache connection.
68-
69-
- **class** - This is the Java class of the driver for the cache engine.
70-
- **bundleName** - Optional. The name of the OSGI bundle to load the `class` from.
71-
- **bundleVersion** - Optional. The version of the OSGI bundle to load the `class` from.
72-
- **storage** - A boolean that flags whether this cache can be used for client or session storage.
73-
- **custom** - A struct of key/value pairs for configuring the cache. This struct is entirely dependent on the cache driver in use, so refer to the docs for that cache driver to see the possible values. Note, some of these custom values might be required for some cache drivers to work.
74-
- **default** - Optional. If you want this cache to be used as a default cache, then give this one of these values: `function`, `object`, `template`, `query`, `resource`, `include`, `http`, `file`, `webservice`.
56+
- **class** - Java class of the cache driver
57+
- **bundleName** - OSGi bundle name (optional)
58+
- **bundleVersion** - OSGi bundle version (optional)
59+
- **storage** - Enable for client/session storage
60+
- **custom** - Driver-specific key/value pairs (check driver docs for required values)
61+
- **default** - Set as default for: `function`, `object`, `template`, `query`, `resource`, `include`, `http`, `file`, `webservice`
7562

7663
## Default Caches
7764

78-
When declaring a cache, you can make it the default cache for creation operations, but it is also possible to configure the default caches for each operation all at once in your `Application.cfc` like so:
65+
Configure default caches for each operation type:
7966

8067
```lucee
8168
this.cache.object = "myCache";
@@ -89,6 +76,4 @@ this.cache.file = "<cache-name>";
8976
this.cache.webservice = "<cache-name>";
9077
```
9178

92-
A single cache can only be the default storage location for a single operation at a time.
93-
94-
For example, a cache named "myCache" cannot both be the default cache for objects as well as queries.
79+
A single cache can only be default for one operation type (e.g. "myCache" can't be default for both objects and queries).

docs/recipes/checksum.md

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@
2222

2323
# Checksum
2424

25-
This document explains how to use a checksum in Lucee.
25+
Validate downloads using checksums provided in response headers.
2626

27-
Many servers provide a checksum for the files they provide for download. We use the checksum to validate a download file in order to avoid a corrupted file.
28-
29-
If you download a file in your application, you can automatically check if the download is valid or not if the necessary info was provided in the response header.
30-
31-
## Example 1
27+
## Download and Validate
3228

3329
```luceescript
3430
<cfscript>
@@ -61,50 +57,20 @@ dump("something went wrong! give it another try?");
6157
</cfscript>
6258
```
6359

64-
- Download the jar file by using cfhttp.
65-
- Dump the file response header. You can see the "X-Checksum-MD5" "X-Checksum-SHA1" keys from the file itself.
66-
- Save the file, and dump(fileInfo(localFile.checksum)). Check to see if the dump matches the value of the downloaded file response["X-Checksum-MD5"] header.
67-
68-
Checksum values are hashed from the binaryfile itself.
69-
70-
```luceescript
71-
dump(hash(fileReadBinary(localFile),"md5"));
72-
dump(hash(fileReadBinary(localFile),"SHA1"));
73-
```
74-
75-
You can validate the checksum as shown below:
76-
77-
```luceescript
78-
// validate file
79-
if(!isEmpty(res.responseheader["X-Checksum-MD5"]?:"")) {
80-
fi=fileInfo("esapi-2.1.0.1.jar");
81-
if(res.responseheader["X-Checksum-MD5"]==fi.checksum) {
82-
dump("we have a match!");
83-
}
84-
else {
85-
fileDelete("esapi-2.1.0.1.jar");
86-
dump("something went wrong! give it another try?");
87-
}
88-
}
89-
```
90-
91-
If the checksum is provided, we can check it. However, the checksum may not always be provided. The following example shows how to provide a checksum for all downloads.
92-
93-
## Example 2
60+
Check `X-Checksum-MD5` or `X-Checksum-SHA1` headers against `fileInfo().checksum` or `hash(fileReadBinary(file), "md5")`.
9461

95-
//download.cfm
62+
## Providing Checksum Headers
9663

9764
```luceescript
9865
<cfscript>
66+
// download.cfm
9967
fi=fileInfo("esapi-2.1.0.1.jar");
10068
header name="Content-MD5" value=fi.checksum;
10169
content file="esapi-2.1.0.1.jar" type="application/x-zip-compressed";
10270
</cfscript>
10371
```
10472

105-
This code allows a downloading application to check if the download was successful or not. Adding the file with header content "Content-MD5" is not required.
106-
107-
Download the file using the below example code:
73+
## Validate with Multiple Header Types
10874

10975
```luceescript
11076
<cfscript>
@@ -148,9 +114,4 @@ dump("something went wrong! give it another try?");
148114
</cfscript>
149115
```
150116

151-
The above code checks and validates the downloaded file.
152-
153-
## Footnotes
154-
155-
You can see the details in this video:
156-
[Checksum](https://www.youtube.com/watch?v=Kb_zSsRDEOg)
117+
Video: [Checksum](https://www.youtube.com/watch?v=Kb_zSsRDEOg)

docs/recipes/component-mappings.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,11 @@
2626

2727
# Component Mappings
2828

29-
Component mappings in Lucee define locations where the server will look for CFML components (CFC files) when using the `createObject()` function or the `new` operator.
29+
A mapping in Lucee is an alias that points to a directory - instead of using full filesystem paths, you use a short name. Lucee has three types: regular mappings (for templates/includes), custom tag mappings (for custom tags), and component mappings (for CFCs).
3030

31-
They provide a way to organize and access your components without having to specify the full path each time.
31+
Component mappings define where Lucee looks for CFCs when using `createObject()` or `new`. This lets you organize and access components without specifying full paths - useful in larger applications with multiple component packages.
3232

33-
## Understanding Component Mappings
34-
35-
Component mappings provide a way to organize and access your CFC files without having to specify the full path each time.
36-
37-
This is particularly useful in large applications with multiple component packages.
38-
39-
**Important**: Component mappings point to the root of package paths, not to individual components.
33+
Mappings point to the root of package paths, not individual components.
4034

4135
For example, if you have a mapping pointing to:
4236

docs/recipes/configuration-administrator-cfc.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
}
1818
-->
1919

20-
# Configure Lucee within your application
20+
# Configure Lucee Programmatically
2121

22-
Lucee provides a web frontend to configure the server and each web context, but you can also do this configuration from within your application.
23-
(For per request settings, please check out the "Application.cfc" section in the [Cookbook](/guides/cookbooks.html)).
22+
Configure Lucee from code using `Administrator.cfc` (for per-request settings, see [[tag-application]]).
2423

2524
## Administrator.cfc
2625

27-
Lucee provides the component "Administrator.cfc" in the package "org.lucee.cfml", a package auto imported in any template, so you can simply use that component as follows:
28-
2926
```cfs
3027
admin = new Administrator("web", "myPassword"); // first argument is the admin type you want to load (web|server), second is the password for the Administrator
3128
dump(admin); // show me the doc for the component
@@ -34,5 +31,4 @@ admin.updateCharset(resourceCharset: "UTF-8"); // set the resource charset
3431

3532
## cfadmin Tag
3633

37-
The component "Administrator" is far from being feature complete, so if you miss a functionality, best consult the unofficial tag "cfadmin" (undocumented) and check out how this tag is used inside the [Lucee Administrator](https://github.com/lucee/Lucee/blob/5.2/core/src/main/java/resource/component/org/lucee/cfml/Administrator.cfc).
38-
Of course, it would be great if you could contribute your addition to the "Administrator" component.
34+
For functionality not in `Administrator.cfc`, check the undocumented `cfadmin` tag usage in the [Lucee Administrator source](https://github.com/lucee/Lucee/blob/7.0/core/src/main/java/resource/component/org/lucee/cfml/Administrator.cfc). Contributions welcome!

docs/recipes/console-logging.md

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,17 @@
2020
}
2121
-->
2222

23-
## Console Logging in Lucee
23+
# Console Logging
2424

25-
Most CFML developers are familiar with using [[tag-dump]] when debugging.
25+
Most CFML developers are familiar with [[tag-dump]] for debugging. [[function-systemoutput]] is similar but writes to the console - useful for CLI scripts, background tasks, and CI environments.
2626

27-
Lucee has a very useful function [[function-systemoutput]], which lets you write messages and dump objects to the console.
27+
Like [[tag-dump]], it can output both text and complex objects. The second argument `addNewLine` controls whether a newline is added (default: `false`).
2828

29-
### What's the console?
29+
## Access the Console
3030

31-
If you are using Tomcat, you can run it interactively using `catalina run` in the `tomcat\bin` directory.
32-
33-
With [[getting-started-commandbox]], you can do similar, via `box server start --console`.
34-
35-
Both then run the Server with the console logs being output.
36-
37-
### What can we log?
38-
39-
Similar to [[tag-dump]], [[function-systemoutput]] can output both text and complex objects.
40-
41-
By default, it doesn't output new lines, the second boolean argument, `addNewLine` does what it says.
42-
43-
### Use with CI like GitHub Actions
44-
45-
When you are running tests remotely, any output from [[function-systemoutput]] is then visible directly in the job log.
31+
- **Tomcat**: `catalina run` in `tomcat\bin`
32+
- **CommandBox**: `box server start --console`
33+
- **CI/CD**: Output appears directly in job logs
4634

4735
## Example
4836

docs/recipes/custom-tag-mappings.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@
2828

2929
# Custom Tag Mappings
3030

31-
Custom tag mappings in Lucee define locations where the server will look for CFML custom tags when you use them in your code.
32-
33-
They provide a way to organize and access your custom tags without having to specify the full path each time or use [[tag-import]] repeatedly.
34-
35-
## Understanding Custom Tag Mappings
36-
37-
Custom tags are reusable CFML templates that you can call like built-in tags. Custom tag mappings tell Lucee where to find these custom tag files.
31+
Custom tags are reusable CFML templates (`.cfm` files) that you can call like built-in tags. Custom tag mappings tell Lucee where to find these files, so you don't have to specify full paths or use [[tag-import]] repeatedly.
3832

3933
For example, if you have a custom tag file at:
4034

docs/recipes/datasource-how-to-define-them.md

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,28 @@
1818
}
1919
-->
2020

21-
# Datasource - How to define them
21+
# Datasources
2222

23-
To execute queries, you need a datasource definition, which points to a specific local or remote datasource. There are different ways to do so.
23+
Define datasources to execute queries against local or remote databases.
2424

25-
## Create a Datasource in the Administrator
25+
## Lucee Administrator
2626

27-
The most common way to define a datasource is in the Lucee Server or Web Administrator. The only difference between the Web and Server Administrator is that datasources defined in the Server Administrator are visible to all web contexts, while datasources defined in the Web Administrator are only visible to the current web context.
28-
29-
In your Administrator, go to the Page "Services/Datasource", in the section "create new Datasource" choose a name for your datasource and the type of your Datasource, for example "MySQL".
27+
Go to Services > Datasource, create a new datasource by choosing a name and type (e.g. MySQL).
3028

3129
![create datasource](https://bitbucket.org/repo/rX87Rq/images/3802808059-createds.png)
3230

33-
On the following page, you can define settings to connect to your datasource. The look and feel of this page depend on the datasource type used. After saving this page, you get back to the overview page and you will get feedback if Lucee was able to connect to your datasource or not.
31+
Configure connection settings on the next page. Server Administrator datasources are visible to all web contexts; Web Administrator datasources only to the current context.
3432

35-
## Create a Datasource in the Application.cfc
33+
## Application.cfc
3634

37-
You cannot only define a datasource in the Lucee Administrator, you can also do this in the [application-context-guide]. The easiest way to do so is to create a datasource in the Administrator (see above) and then go to the detail view of this datasource by clicking the "edit button".
35+
Create a datasource in Administrator, then click "edit" to view its definition:
3836

3937
![select datasource](https://bitbucket.org/repo/rX87Rq/images/4142224660-select-datasource.png)
4038

41-
At the bottom of the detail page, you find a box that will look like this:
39+
Copy the code from the bottom of the detail page:
4240

4341
![datasource application definition](https://bitbucket.org/repo/rX87Rq/images/1656402808-datasource-app-def.png)
4442

45-
You can simply copy the code inside the box to your [application-context-guide] body, and Lucee will pick up this definition. After that, you can delete the datasource from the Administrator.
46-
4743
```cfs
4844
this.datasources["myds"] = {
4945
class: 'org.gjt.mm.mysql.Driver',
@@ -53,7 +49,7 @@ this.datasources["myds"] = {
5349
};
5450
```
5551

56-
Alternatively, you can also use this pattern:
52+
Or use this pattern:
5753

5854
```cfs
5955
this.datasources["myds"] = {
@@ -75,13 +71,13 @@ this.datasources["myds"] = {
7571

7672
### Default Datasource
7773

78-
With the [application-context-guide], you can also define a default datasource that is used if no "datasource" attribute is defined with the tag cfquery, cfstoredproc, cfinsert, cfupdate, etc. Simply do the following:
74+
Define a default datasource used when no `datasource` attribute is specified in `cfquery`, `cfstoredproc`, etc.:
7975

8076
```cfs
8177
this.defaultdatasource = "myds";
8278
```
8379

84-
In that case, the datasource "myds" is used if there is no datasource defined. Instead of defining a datasource name, you can also define the datasource directly as follows:
80+
Or define the datasource inline:
8581

8682
```cfs
8783
this.datasource = {
@@ -91,3 +87,41 @@ this.datasource = {
9187
password: 'encrypted:5120611ea34c6123fd85120a0c27ab23fd81ea34cb854'
9288
};
9389
```
90+
91+
### Custom JDBC Drivers (Other)
92+
93+
When using the "Other - JDBC Driver" type for databases without built-in support, provide:
94+
95+
- **class**: The fully qualified JDBC driver class name
96+
- **connectionString**: The JDBC connection URL
97+
98+
```cfs
99+
this.datasources["mydb"] = {
100+
class: 'com.example.jdbc.Driver',
101+
connectionString: 'jdbc:example://localhost:1234/mydb',
102+
username: 'user',
103+
password: 'pass'
104+
};
105+
```
106+
107+
For OSGi-based JDBC drivers (JARs deployed as bundles in `/lucee-server/bundles/`), you can also specify:
108+
109+
- **bundleName**: The OSGi bundle symbolic name
110+
- **bundleVersion**: The OSGi bundle version
111+
112+
```cfs
113+
this.datasources["mydb"] = {
114+
class: 'com.example.jdbc.Driver',
115+
connectionString: 'jdbc:example://localhost:1234/mydb',
116+
bundleName: 'com.example.jdbc',
117+
bundleVersion: '1.2.3',
118+
username: 'user',
119+
password: 'pass'
120+
};
121+
```
122+
123+
This is useful when:
124+
125+
- Using database drivers not bundled with Lucee
126+
- Deploying drivers as OSGi bundles for better version management
127+
- Working with multiple versions of the same driver

docs/recipes/directory-placeholders.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
## Directory Placeholders ##
1919

20-
In order to make configuring Lucee a little easier, there are several constants (we call them "directory placeholders") that contain a certain value which might change depending on the system, the environment or the context.
20+
Directory placeholders are constants you can use in Lucee configuration instead of hardcoding paths. They resolve to actual paths at runtime, making your config portable across different systems and environments.
2121

2222
### Available Directory Placeholders ###
2323

0 commit comments

Comments
 (0)