OrmLiteCacheClient and keys containing square brackets

I’ve come across an issue where my cache keys contain a square bracket, and I want to match keys using the OrmLiteCacheClient created using the SqlServerDialect.Provider.

An example key I have is:


In my code, I’m trying to match using this:

var keys = Cache.GetKeysStartingWith(@"urn:ServiceStack.QueryResponse`1\[JiwaFinancials.Jiwa.JiwaServiceModel.Tables.IN_Main\]").ToList();

But that yields no keys.

In observing the SQL being issued using SQL Profiler, I see this:

exec sp_executesql N'SELECT "Id", "Data", "ExpiryDate", "CreatedDate", "ModifiedDate" FROM "CacheEntry" WHERE "Id" LIKE @0',N'@0 varchar(8000)',@0='urn:ServiceStack.QueryResponse`1\JiwaFinancials.Jiwa.JiwaServiceModel.Tables.IN_Main\]:%'

But this will return 0 rows because the ESCAPE clause needs to be provided - so for instance this query returns the correct results:

SELECT * FROM CacheEntry WHERE Id LIKE 'urn:ServiceStack.QueryResponse`1\[JiwaFinancials.Jiwa.JiwaServiceModel.Tables.IN_Main\]:%' ESCAPE '\'

Is there a way to cause the OrmLiteCacheClient to correctly escape the query text?

EDIT: Escaping the \ correctly

There wasn’t, but I’ve just added support for specifying an LIKE Escape sequence char from this commit, now available in the latest v6.6.1+ on GitHub Packages with:

new OrmLiteCacheClient {
    LikeEscapeChar = '\\'

Unfortunately MyGet has become unreliable again, so they’re only available on GitHub packages until we can deploy a new version on MyGet again.

1 Like

Awesome - thanks heaps!

1 Like