{"_id":"5698f130cb127f0d003cc06a","githubsync":"","category":{"_id":"568a404e050eb50d00c07999","__v":7,"pages":["568a404f050eb50d00c0799b","5698f130cb127f0d003cc06a","5698f1483da4370d009d2079","569e6013d233620d00705550","569f3e578f6d4b0d00f13bd5","56a9d3d43b04f20d00eccaa5","56cc2b9e94c8f00b00b83d76"],"project":"568a404d050eb50d00c07995","version":"568a404e050eb50d00c07998","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-01-04T09:50:06.816Z","from_sync":false,"order":9999,"slug":"documentation","title":"Documentation"},"project":"568a404d050eb50d00c07995","__v":32,"user":"55e84e0f0693802d00bc6952","version":{"_id":"568a404e050eb50d00c07998","project":"568a404d050eb50d00c07995","__v":2,"createdAt":"2016-01-04T09:50:06.218Z","releaseDate":"2016-01-04T09:50:06.218Z","categories":["568a404e050eb50d00c07999","56cc2b81272aa4130002cce9"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-01-15T13:16:32.164Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"BlazingCache is a fast ***distributed*** ***cache***.\n\nWe use cache because we want to access data in a very fast way with no need to read from a database or perform other expensive operations. This pose a problem: you can read data from your cache but you need to invalidate it when the value you stored on the cache is no longer valid, i.e when it gets \"stale\".\n\nLet's use a simple database example: if you are performing the same query lots of times, why not caching the result and storing it in a local variable? For instance, if you steadily issue the \"SELECT * FROM FOO WHERE ID=1\" query, you can save the result to a cache assigning the value to the \"1\" key. Then, when you update the row at ID=1, you need to invalidate the cache and tell the system that the value stored in the cache is now no longer valid.\n\nWhat does ***distributed*** mean?\n\nYou can think of a cache as a (Java) Map such as ConcurrentHashMap implementation, for instance. When you adopt a ConcurrentHashMap, you are not going to be able to run your code in more than a single JVM: indeed, any invalidation issued needs to be propagated to other JVMs, otherwise other caches would contain stale data at the time of the first invalidation.\n\nBlazingCache simply coordinates the job of distributedly invalidating cache entries so as to ensure overall data consistency,  and also add some minor functionality such as managing data expiration and memory limits.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Why not use another distibuted cache implementation?\"\n}\n[/block]\nWith BlazingCache you will get \"only\" a distributed cache. Usually distributed cache implementations from vendors offer plenty of functions (e.g. computing grids components) but, in case you need **only** a cache which \"works well\", maybe BlazingCache is the answer to your needs.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"How does BlazingCache work in a distributed environment?\"\n}\n[/block]\nIn local mode BlazingCache is no more than a ConcurrentHashMap, providing a few more cache functionalities such as entry expiration and the ability to fix an upper bound to the memory used by the cache itself.\n\nIn distributed mode, it works in a fashion pretty much similar to local mode, with the additional guarantee of the following properties:\n  * If a client invalidates a key or performs a \"put\", the function blocks until all other clients hosting the same entry perform the same invalidation.\n  * When a client performs a \"put\", the corresponding event is notified to the server which, in turn, broadcast the new value to any other client known to have the same entry in memory.\n  * Conflicts and locks are resolved by the system automatically, any \"problem\" resulting in invalidation of the entry which is in \"doubt\".\n \nThe invalidation works in a very simple manner: when a client invalidates an entry, this is invalidated  locally: afterwards, the client issues an invalidate message to the cache server; the latter routes it to any other client which is known to have the same entry in memory.\n\nEvery operation is implemented using asynchronous protocols and the majority of the functions are handled client-side. This means that the cache scales very well and there is no need to use a thread for each client or pending operation.\n\nSince the cache server is only a coordinator of clients, it **does not keep a copy of any value**. In distributed mode, to alleviate the cache misses penalty, the clients have the ability to \"fetch\" data from other connected clients in case of cache miss: this function helps to reduce the load on database by reading data from other peers instead of falling back to cache misses.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"What about network problems? High Availability?\"\n}\n[/block]\nBlazingCache server is very fast but makes a very important assumption on clients:\n  * when a client is disconnected, its cache is empty.\n\nThe same assumption is made from the client:\n  * If no connection is active to the server my local cache is empty.\n\nThis fail-fast way of working handles very well the case of slow clients/network problems and simplifies handling the state of clients from the server point of view.\n\nFurthermore, from the client perspective, this means that if there is no connection to the server the cache is considered empty and \"invalidations\"/\"puts\" cannot be completed; this kind of operations will then be blocked until a configured timeout is reached.\n\nYou can start more than one server at the same time, but only one will serve connections for clients, the other will work in backup mode and, in case of failure of the current leader,  take leadership. This also means that there is little reason to put in production more than two or three cache servers.","excerpt":"","slug":"how-does-it-work","type":"basic","title":"How does It work"}
BlazingCache is a fast ***distributed*** ***cache***. We use cache because we want to access data in a very fast way with no need to read from a database or perform other expensive operations. This pose a problem: you can read data from your cache but you need to invalidate it when the value you stored on the cache is no longer valid, i.e when it gets "stale". Let's use a simple database example: if you are performing the same query lots of times, why not caching the result and storing it in a local variable? For instance, if you steadily issue the "SELECT * FROM FOO WHERE ID=1" query, you can save the result to a cache assigning the value to the "1" key. Then, when you update the row at ID=1, you need to invalidate the cache and tell the system that the value stored in the cache is now no longer valid. What does ***distributed*** mean? You can think of a cache as a (Java) Map such as ConcurrentHashMap implementation, for instance. When you adopt a ConcurrentHashMap, you are not going to be able to run your code in more than a single JVM: indeed, any invalidation issued needs to be propagated to other JVMs, otherwise other caches would contain stale data at the time of the first invalidation. BlazingCache simply coordinates the job of distributedly invalidating cache entries so as to ensure overall data consistency, and also add some minor functionality such as managing data expiration and memory limits. [block:api-header] { "type": "basic", "title": "Why not use another distibuted cache implementation?" } [/block] With BlazingCache you will get "only" a distributed cache. Usually distributed cache implementations from vendors offer plenty of functions (e.g. computing grids components) but, in case you need **only** a cache which "works well", maybe BlazingCache is the answer to your needs. [block:api-header] { "type": "basic", "title": "How does BlazingCache work in a distributed environment?" } [/block] In local mode BlazingCache is no more than a ConcurrentHashMap, providing a few more cache functionalities such as entry expiration and the ability to fix an upper bound to the memory used by the cache itself. In distributed mode, it works in a fashion pretty much similar to local mode, with the additional guarantee of the following properties: * If a client invalidates a key or performs a "put", the function blocks until all other clients hosting the same entry perform the same invalidation. * When a client performs a "put", the corresponding event is notified to the server which, in turn, broadcast the new value to any other client known to have the same entry in memory. * Conflicts and locks are resolved by the system automatically, any "problem" resulting in invalidation of the entry which is in "doubt". The invalidation works in a very simple manner: when a client invalidates an entry, this is invalidated locally: afterwards, the client issues an invalidate message to the cache server; the latter routes it to any other client which is known to have the same entry in memory. Every operation is implemented using asynchronous protocols and the majority of the functions are handled client-side. This means that the cache scales very well and there is no need to use a thread for each client or pending operation. Since the cache server is only a coordinator of clients, it **does not keep a copy of any value**. In distributed mode, to alleviate the cache misses penalty, the clients have the ability to "fetch" data from other connected clients in case of cache miss: this function helps to reduce the load on database by reading data from other peers instead of falling back to cache misses. [block:api-header] { "type": "basic", "title": "What about network problems? High Availability?" } [/block] BlazingCache server is very fast but makes a very important assumption on clients: * when a client is disconnected, its cache is empty. The same assumption is made from the client: * If no connection is active to the server my local cache is empty. This fail-fast way of working handles very well the case of slow clients/network problems and simplifies handling the state of clients from the server point of view. Furthermore, from the client perspective, this means that if there is no connection to the server the cache is considered empty and "invalidations"/"puts" cannot be completed; this kind of operations will then be blocked until a configured timeout is reached. You can start more than one server at the same time, but only one will serve connections for clients, the other will work in backup mode and, in case of failure of the current leader, take leadership. This also means that there is little reason to put in production more than two or three cache servers.