Example #1
0
 ValueTask<IMartenDatabase> IMartenStorage.FindOrCreateDatabase(string tenantIdOrDatabaseIdentifier)
 {
     return Tenancy.FindOrCreateDatabase(tenantIdOrDatabaseIdentifier);
 }
 public void SetTenancyDetails(string tenancyRef, Tenancy tenancy)
 {
     StoredTenancyDetails[tenancyRef] = tenancy;
 }
Example #3
0
 async ValueTask<IReadOnlyList<IMartenDatabase>> IMartenStorage.AllDatabases()
 {
     var databases = await Tenancy.BuildDatabases().ConfigureAwait(false);
     return databases.OfType<IMartenDatabase>().ToList();
 }
Example #4
0
        private static void Main(string[] args)
        {
            // unless otherwise stated, all values presented are the default if not specified
            var memory = MemoryBox.GetInstance(
                new MemoryConfiguration {
                DefaultTimeToLive       = new TimeSpan(1, 0, 0, 0),
                DefaultTimeToRefresh    = new TimeSpan(0, 0, 5, 0),
                ExpirationScanFrequency = new TimeSpan(0, 1, 0, 0),
                PoolSize = 1     // hardcoded to 1 on creation of connectionpool
            });

            // redis connection assumes SSL is enabled; if not you must adjust port and UseSSL
            var redis = RedisBox.GetInstance(
                new RedisConfiguration {
                DatabaseID           = 0,
                DefaultTimeToLive    = new TimeSpan(1, 0, 0, 0),
                DefaultTimeToRefresh = new TimeSpan(0, 0, 5, 0),
                Host     = "<host>",     // defaults to 127.0.0.1
                Password = "******", // only required if using ssl, defaults to ""
                PoolSize = 5,
                Port     = 6379,         // defaults to 6380
                UseSSL   = false         // defaults to true
            });

            // for documentDB you must replace the string values with whatever you have setup
            // the backing DB of your cosmosDB MUST be SQL and partitioned/sharded based on /_partitionKey
            var documentDB = DocumentDBBox.GetInstance(
                new DocumentDBConfiguration {
                Collection           = "<collection>",
                ConnectionPolicy     = new ConnectionPolicy(), // defaults to nothing configured
                Database             = "<database>",
                DefaultTimeToLive    = new TimeSpan(1, 0, 0, 0),
                DefaultTimeToRefresh = new TimeSpan(0, 0, 5, 0),
                EndpointURI          = new Uri("https://<account>.documents.azure.com:443"),
                PartitionKey         = "cache", // defaults to cache, but you can specify what you want
                PoolSize             = 5,
                PrimaryKey           = "<auth_key>"
            });

            // create a new tenancy object`
            var tenancy = new Tenancy(
                new ILitterBox[] {
                memory,
                redis,
                documentDB
            });

            // subscribe to internal errors
            tenancy.ExceptionEvent += TenancyOnExceptionEvent;

            // set an item (will backfill all three caches)
            var x = tenancy.SetItem(
                "foo",
                new LitterBoxItem <dynamic> {
                Value = new {
                    Args = "boo"
                }
            }).GetAwaiter().GetResult();

            // get item from cache, checks in order of array initialization. in this case memory -> redis -> documentDB
            var y = tenancy.GetItem <dynamic>("foo").GetAwaiter().GetResult();

            Console.ReadKey();
        }