Skip to content

Add cache usage option "never" #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 17 additions & 38 deletions src/FluentNHibernate/Mapping/CachePart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,32 @@ namespace FluentNHibernate.Mapping;

public class CachePart(Type entityType) : ICacheMappingProvider
{
readonly AttributeStore attributes = new AttributeStore();
readonly AttributeStore attributes = new();

/// <summary>
/// Sets caching to read-write
/// </summary>
public CachePart ReadWrite()
{
attributes.Set("Usage", Layer.UserSupplied, "read-write");
return this;
}
public CachePart ReadWrite() => CustomUsage("read-write");

/// <summary>
/// Sets caching to non-strict read-write
/// </summary>
public CachePart NonStrictReadWrite()
{
attributes.Set("Usage", Layer.UserSupplied, "nonstrict-read-write");
return this;
}
public CachePart NonStrictReadWrite() => CustomUsage("nonstrict-read-write");

/// <summary>
/// Sets caching to read-only
/// </summary>
public CachePart ReadOnly()
{
attributes.Set("Usage", Layer.UserSupplied, "read-only");
return this;
}
public CachePart ReadOnly() => CustomUsage("read-only");

/// <summary>
/// Sets caching to transactional
/// </summary>
public CachePart Transactional()
{
attributes.Set("Usage", Layer.UserSupplied, "transactional");
return this;
}
public CachePart Transactional() => CustomUsage("transactional");

/// <summary>
/// Sets caching to never
/// </summary>
public CachePart Never() => CustomUsage("never");

/// <summary>
/// Specifies a custom cache behaviour
Expand All @@ -68,20 +57,12 @@ public CachePart Region(string name)
/// Include all properties for caching
/// </summary>
/// <returns></returns>
public CachePart IncludeAll()
{
attributes.Set("Include", Layer.UserSupplied, "all");
return this;
}
public CachePart IncludeAll() => CustomInclude("all");

/// <summary>
/// Include only non-lazy properties for caching
/// </summary>
public CachePart IncludeNonLazy()
{
attributes.Set("Include", Layer.UserSupplied, "non-lazy");
return this;
}
public CachePart IncludeNonLazy() => CustomInclude("non-lazy");

/// <summary>
/// Specify a custom property inclusion strategy
Expand All @@ -95,11 +76,9 @@ public CachePart CustomInclude(string custom)

internal bool IsDirty => attributes.IsSpecified("Region") || attributes.IsSpecified("Usage") || attributes.IsSpecified("Include");

CacheMapping ICacheMappingProvider.GetCacheMapping()
{
var mapping = new CacheMapping(attributes.Clone());
mapping.ContainedEntityType = entityType;

return mapping;
}
CacheMapping ICacheMappingProvider.GetCacheMapping() =>
new(attributes.Clone())
{
ContainedEntityType = entityType
};
}