For a second-level cache, you must clear it using ISessionFactory.Evict(typeof(T)); . For the first level cache, you can simply call ISession.Clear(); .
And if you do not know when you need to clear the second level cache, you should send some information from another application to this application (via sockets or webservice ...). If this is not possible, you can create a table in the database that tells you when the data in the database was last modified, and then check the record in this table. If it has been changed, you clear the caches. Just make sure the record is updated every time some other application changes the database (you can do this using triggers or check system tables).
If you use triggers, remember to ignore the entry if you are updating nhibernate. You can do this with some variable that has the latest update time set for it, and compare it with this.
source share