How does Freeze deal with idempotent?

In a nutshell, it doesn't: Freeze treats idempotent operations exactly the same as normal operations. That is because both read-only and update operations may be idempotent:

Slice
interface Example
{
    idempotent int getVal();
    idempotent void setVal(int val);
}

Both getVal and setVal are idempotent operations, but only getVal is read-only; setVal is idempotent even though it modifies state in the server.

What Freeze cares about or, more precisely, what a Freeze evictor cares about, is not whether an operation is idempotent or not, but whether an operation modifies state in the server. (Operations that modify state are known as mutating operations; operations that do not are known as non-mutating operations.) You can inform Freeze whether an operation is mutating or not with a metadata directive:

Slice
interface Example
{
    ["freeze:read"] idempotent int getVal();
    ["freeze:write"] idempotent void setVal(int val);
}

These metadata directives mark getVal as a non-mutating operation, and setVal as a mutating operation. A Freeze evictor needs to know whether an operation is non-mutating in order to decide how to deal with a request; depending on the evictor, it may use different strategies to deal with the database. For example, with a transactional evictor, mutating operations are performed in separate transactions whereas non-mutating operations can be completed without accessing the database at all if the data is already in the evictor's cache.

If you do not specify any metadata directive, Freeze assumes that the corresponding operation is non-mutating. It follows that you must mark all operations that are mutating with a freeze:write metadata directive.

See Also