[[custom_interceptors_chapter]]
= Custom Interceptors

[IMPORTANT]
====
Custom interceptors are deprecated in {brandname} and will be removed in a
future version.
====

Custom interceptors are a way of extending {brandname} by being able to influence or respond to any modifications to cache. Example of such modifications are: elements are added/removed/updated or transactions are committed.

== Adding custom interceptors declaratively
Custom interceptors can be added on a per named cache basis. This is because each named cache have its own interceptor stack. Following xml snippet depicts the ways in which a custom interceptor can be added.

[source,xml,options="nowrap",subs=attributes+]
----
include::xml/custom_interceptors.xml[]
----

== Adding custom interceptors programmatically
In order to do that one needs to obtain a reference to the link:../../apidocs/org/infinispan/AdvancedCache.html[`AdvancedCache`]. This can be done as follows:

[source,java]
----
include::code_examples/CustomInterceptors.java[]
----

Then one of the _addInterceptor()_ methods should be used to add the actual interceptor. For further documentation refer to link:../../apidocs/org/infinispan/AdvancedCache.html[`AdvancedCache`] javadoc.

== Custom interceptor design
When writing a custom interceptor, you need to abide by the following rules.

* Custom interceptors must declare a public, empty constructor to enable construction.
* Custom interceptors will have setters for any property defined through property tags used in the XML configuration.
