README.md in macaw_framework-1.3.0 vs README.md in macaw_framework-1.3.1
- old
+ new
@@ -16,11 +16,11 @@
+ [Caching: Improve performance by caching responses and configuring cache invalidation](#caching-improve-performance-by-caching-responses-and-configuring-cache-invalidation)
+ [Session management: Handle user sessions securely with server-side in-memory storage](#session-management-handle-user-sessions-securely-with-server-side-in-memory-storage)
+ [Configuration: Customize various aspects of the framework through the application.json configuration file, such as rate limiting, SSL support, and Prometheus integration](#configuration-customize-various-aspects-of-the-framework-through-the-applicationjson-configuration-file-such-as-rate-limiting-ssl-support-and-prometheus-integration)
+ [Monitoring: Easily monitor your application performance and metrics with built-in Prometheus support](#monitoring-easily-monitor-your-application-performance-and-metrics-with-built-in-prometheus-support)
+ [Routing for "public" Folder: Serve Static Assets](#routing-for-public-folder-serve-static-assets)
- + [Cron Jobs](#cron-jobs)
+ + [Periodic Jobs](#periodic-jobs)
+ [Tips](#tips)
* [Contributing](#contributing)
* [License](#license)
* [Code of Conduct](#code-of-conduct)
@@ -49,11 +49,11 @@
## Compatibility
MacawFramework is built to be highly compatible, since it uses only native Ruby code:
-- **MRI**: MacawFramework is compatible with Matz's Ruby Interpreter (MRI), version 2.7.0 and onwards. If you are using this version or a more recent one, you should not encounter any compatibility issues.
+- **MRI**: MacawFramework is compatible with Matz's Ruby Interpreter (MRI), version 3.0.0 and onwards. If you are using this version or a more recent one, you should not encounter any compatibility issues.
- **TruffleRuby**: TruffleRuby is another Ruby interpreter that is fully compatible with MacawFramework. This provides developers with more flexibility in their choice of Ruby interpreter.
- **JRuby**: MacawFramework is also compatible with JRuby, a version of Ruby that runs on the Java Virtual Machine (JVM).
@@ -102,17 +102,30 @@
```
### Caching: Improve performance by caching responses and configuring cache invalidation
```ruby
+m = MacawFramework::Macaw.new
+
m.get('/cached_data', cache: ["header_to_cache", "query_param_to_cache"]) do |context|
# Retrieve data
end
```
*Observation: To activate caching, you also have to set its properties in the `application.json` file. If you don't, the caching strategy will not work. See the Configuration section below for more details.*
+Another method of cache is the manual cache via the `MacawFramework::Cache` class. You can manually
+call the `read` and `write` methods of this singleton to save and recover values inside your methods.
+
+```ruby
+MacawFramework::Cache.write(:name, 'Maria', expires_in: 1800)
+# Your code
+MacawFramework::Cache.read(:name) # Maria
+```
+
+Manual cache does not need any additional configuration.
+
### Session management: Handle user sessions with server-side in-memory storage
Session will only be enabled if it's configurations exists in the `application.json` file.
The session mechanism works by recovering the Session ID from a client sent header. The default
header is `X-Session-ID`, but it can be changed in the `application.json` file.
@@ -121,10 +134,12 @@
session ID will be automatically generated and sent to a client if this client does not provide
a session id in the HTTP request. In the case of the client sending an ID of an expired session
the framework will return a new session with a new ID.
```ruby
+m = MacawFramework::Macaw.new
+
m.get('/login') do |context|
# Authenticate user
context[:client][:user_id] = user_id
end
@@ -193,20 +208,22 @@
are made. For example, if you have an image file named "logo.png" inside a "img" folder in the "public" folder, it will
be accessible at http://yourdomain.com/img/logo.png without any additional configuration.
#### Caution: This is incompatible with most non-unix systems, such as Windows. If you are using a non-unix system, you will need to manually configure the "public" folder and use dir as nil to avoid problems.
-### Cron Jobs
+### Periodic Jobs
-Macaw Framework supports the declaration of cron jobs right in your application code. This feature allows developers to
+Macaw Framework supports the declaration of periodic jobs right in your application code. This feature allows developers to
define tasks that run at set intervals, starting after an optional delay. Each job runs in a separate thread, meaning
-your cron jobs can execute in parallel without blocking the rest of your application.
+your periodic jobs can execute in parallel without blocking the rest of your application.
-Here's an example of how to declare a cron job:
+Here's an example of how to declare a periodic job:
```ruby
+m = MacawFramework::Macaw.new
+
m.setup_job(interval: 5, start_delay: 5, job_name: "cron job 1") do
- puts "i'm a cron job that runs every 5 secs!"
+ puts "i'm a periodic job that runs every 5 secs!"
end
```
Values for interval and start_delay are in seconds.