User Guide

Everything you need to install, configure, and build with Montycat — from getting started to governance, advanced operations, and security.

Montycat maintains in-memory data and uses a background timer task to automatically remove in-memory records that are set to expire.
The timer interval is set to 1 second by default.
At each interval, Montycat checks for expired records and removes them from memory.
If a 1-second interval is not required, the check rate can be configured to match your application's needs.

montycat expiration-check 10

or

montycat console
> expiration-check 10

exit

If you use containerized Montycat you can change environmental variable MONTYCAT_EXPIRATION_RATE to set a new value for timer check rate.
That new value will be saved in the configuration file.

FROM montygovernance/montycat:latest

# MONTYCAT_EXPIRATION_RATE default is 1 second
# Override it by setting it to your desired value in seconds
# It's recommended to set it to at least 5 seconds for heavy workloads in production systems

ENV MONTYCAT_EXPIRATION_RATE=10

You can also change the expiration check rate directly from the client (requires superowner credentials):

# Set how often the server scans for expired in-memory keys, in whole seconds
# (rate=10 -> a scan every 10 seconds). Stored as-is, like the snapshot rate.
# Defaults to 1 second. Requires superowner credentials.
await connection.set_expiration_check_rate(10)

# {"status": True, "payload": "Expiration-check rate updated", "error": None}

If you insert into in-memory keyspace, you can set optional expiration argument in seconds.
Database timer will remove the record when time marker you set reached.
Timer works as a non-blocking background task.

from keyspaces import EmployeesInMem #keyspaces.py
from schemas import EmployeesSchema #schemas.py

array = [
  {"username": "Name1", "location": "Location1", "age": 22},
  {"username": "Name2", "location": "Location2", "age": 23},
  {"username": "Name3", "location": "Location3", "age": 24},
]

res1 = await EmployeesInMem.insert_bulk(bulk_values=array, expire_sec=60 * 60)
res2 = await EmployeesInMem.insert_custom_key(custom_key="myCustomKey", expire_sec=60 * 60)
res3 = await EmployeesInMem.insert_custom_key_value(custom_key="myCustomKey", value="John", expire_sec=60 * 60)
res4 = await EmployeesInMem.insert_value({"username": "John", "age": 28}, expire_sec=60 * 60)

You can update an expiration time for a single record for records in in-memory keyspaces.

#main.py
from keyspaces import EmployeesInMem #keyspaces.py
from schemas import EmployeesSchema

value = EmployeesSchema(
    username = "Name",
    location = "Location",
    age = 21
).serialize()

res1 = await EmployeesInMem.insert_value(value, expire_sec=60 * 60)

# {"status": True, "payload": "128222336824100726154851618391811195396", "error": None}

res2 = await EmployeesInMem.update_value(key="128222336824100726154851618391811195396", age=22, expire_sec=60 * 120)

# {"status": True, "payload": None, "error": None}