Skip to content

Commit 242c561

Browse files
authored
Add cache usage option "never" (#697)
Fixes #528 +semver:feature
1 parent 363709d commit 242c561

File tree

1 file changed

+17
-38
lines changed

1 file changed

+17
-38
lines changed

src/FluentNHibernate/Mapping/CachePart.cs

+17-38
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,32 @@ namespace FluentNHibernate.Mapping;
66

77
public class CachePart(Type entityType) : ICacheMappingProvider
88
{
9-
readonly AttributeStore attributes = new AttributeStore();
9+
readonly AttributeStore attributes = new();
1010

1111
/// <summary>
1212
/// Sets caching to read-write
1313
/// </summary>
14-
public CachePart ReadWrite()
15-
{
16-
attributes.Set("Usage", Layer.UserSupplied, "read-write");
17-
return this;
18-
}
14+
public CachePart ReadWrite() => CustomUsage("read-write");
1915

2016
/// <summary>
2117
/// Sets caching to non-strict read-write
2218
/// </summary>
23-
public CachePart NonStrictReadWrite()
24-
{
25-
attributes.Set("Usage", Layer.UserSupplied, "nonstrict-read-write");
26-
return this;
27-
}
19+
public CachePart NonStrictReadWrite() => CustomUsage("nonstrict-read-write");
2820

2921
/// <summary>
3022
/// Sets caching to read-only
3123
/// </summary>
32-
public CachePart ReadOnly()
33-
{
34-
attributes.Set("Usage", Layer.UserSupplied, "read-only");
35-
return this;
36-
}
24+
public CachePart ReadOnly() => CustomUsage("read-only");
3725

3826
/// <summary>
3927
/// Sets caching to transactional
4028
/// </summary>
41-
public CachePart Transactional()
42-
{
43-
attributes.Set("Usage", Layer.UserSupplied, "transactional");
44-
return this;
45-
}
29+
public CachePart Transactional() => CustomUsage("transactional");
30+
31+
/// <summary>
32+
/// Sets caching to never
33+
/// </summary>
34+
public CachePart Never() => CustomUsage("never");
4635

4736
/// <summary>
4837
/// Specifies a custom cache behaviour
@@ -68,20 +57,12 @@ public CachePart Region(string name)
6857
/// Include all properties for caching
6958
/// </summary>
7059
/// <returns></returns>
71-
public CachePart IncludeAll()
72-
{
73-
attributes.Set("Include", Layer.UserSupplied, "all");
74-
return this;
75-
}
60+
public CachePart IncludeAll() => CustomInclude("all");
7661

7762
/// <summary>
7863
/// Include only non-lazy properties for caching
7964
/// </summary>
80-
public CachePart IncludeNonLazy()
81-
{
82-
attributes.Set("Include", Layer.UserSupplied, "non-lazy");
83-
return this;
84-
}
65+
public CachePart IncludeNonLazy() => CustomInclude("non-lazy");
8566

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

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

98-
CacheMapping ICacheMappingProvider.GetCacheMapping()
99-
{
100-
var mapping = new CacheMapping(attributes.Clone());
101-
mapping.ContainedEntityType = entityType;
102-
103-
return mapping;
104-
}
79+
CacheMapping ICacheMappingProvider.GetCacheMapping() =>
80+
new(attributes.Clone())
81+
{
82+
ContainedEntityType = entityType
83+
};
10584
}

0 commit comments

Comments
 (0)