Skip to content

Commit ad9a666

Browse files
committed
Add note on directly injecting SqliteCache to README
This is required when the required method/operation doesn't have an analog in the IDistributedCache façade.
1 parent 2fe149c commit ad9a666

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,29 @@ public class FooModel(DbContext db, IDistributedCache cache)
8585
}
8686
```
8787

88+
To take advantage of SqliteCache-specific features or functionality that aren't exposed via the `IDistributedCache` façade, you'll need to inject `SqliteCache` into your classes/methods rather than `IDistributedCache`. For example, to globally clear the cache after performing some operation:
89+
90+
```csharp
91+
// using NeoSmart.Caching.Sqlite;
92+
public class BarModel(DbContext db, SqliteCache cache)
93+
{
94+
_db = db;
95+
_cache = cache;
96+
}
97+
98+
public ActionResult OnPostAsync()
99+
{
100+
...
101+
await _db.SomethingDestructiveAsync();
102+
103+
// We need to invalidate all the cache, since it's too hard to
104+
// account for the changes this operation caused for legacy reasons.
105+
await _cache.ClearAsync();
106+
107+
...
108+
}
109+
```
110+
88111
## License
89112

90113
SqliteCache is developed and maintained by Mahmoud Al-Qudsi of NeoSmart Technologies. The project is

0 commit comments

Comments
 (0)